changeset 1387:3f9176617565

Added library functions to handle reading of datatype, sign and valid range, plus writing of valid range and setting of default ranges. These functions properly handle differences between valid_range type and image type. Such difference can cause valid data to appear as invalid when double to float conversion causes rounding in the wrong direction (out of range). Modified voxel_loop, volume_io and programs to use these functions.
author neelin <neelin>
date Thu, 16 Aug 2001 16:41:31 +0000
parents 3bddec09c6f9
children 6aeb0603f3c3
files libsrc/image_conversion.c libsrc/minc.h libsrc/minc_convenience.c progs/Proglib/voxel_loop.c progs/minccalc/gram.c progs/mincconcat/mincconcat.c progs/mincexample/mincexample1.c progs/mincexample/mincexample2.c progs/mincextract/mincextract.c progs/mincinfo/mincinfo.c progs/mincreshape/mincreshape.c progs/minctoraw/minctoraw.c progs/rawtominc/rawtominc.c volume_io/Volumes/input_mnc.c volume_io/Volumes/output_mnc.c
diffstat 15 files changed, 206 insertions(+), 346 deletions(-) [+]
line wrap: on
line diff
--- a/libsrc/image_conversion.c
+++ b/libsrc/image_conversion.c
@@ -34,7 +34,15 @@
 @CREATED    : July 27, 1992. (Peter Neelin, Montreal Neurological Institute)
 @MODIFIED   : 
  * $Log: image_conversion.c,v $
- * Revision 6.3  2001-08-16 13:32:18  neelin
+ * Revision 6.4  2001-08-16 16:41:31  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.3  2001/08/16 13:32:18  neelin
  * Partial fix for valid_range of different type from image (problems
  * arising from double to float conversion/rounding). NOT COMPLETE.
  *
@@ -116,7 +124,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/image_conversion.c,v 6.3 2001-08-16 13:32:18 neelin Exp $ MINC (MNI)";
+static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/image_conversion.c,v 6.4 2001-08-16 16:41:31 neelin Exp $ MINC (MNI)";
 #endif
 
 #include <type_limits.h>
@@ -950,33 +958,11 @@
 
    MI_SAVE_ROUTINE_NAME("MI_icv_get_vrange");
 
-   /* Look for valid range info */
-   oldncopts = ncopts; ncopts = 0;
-   status=miattget(cdfid, varid, MIvalid_range, NC_DOUBLE, 2, vrange, &length);
-   if ((status!=MI_ERROR) && (length==2)) {
-      icvp->var_vmax=MAX(vrange[0],vrange[1]);
-      icvp->var_vmin=MIN(vrange[0],vrange[1]);
+   if (miget_valid_range(cdfid, varid, vrange) == MI_ERROR) {
+      MI_RETURN(MI_ERROR);
    }
-   else {
-      status=miattget1(cdfid, varid, MIvalid_max, NC_DOUBLE, 
-                       &(icvp->var_vmax));
-      if (status==MI_ERROR) 
-         icvp->var_vmax=MI_get_default_range(MIvalid_max, 
-                                             icvp->var_type, icvp->var_sign);
-      status=miattget1(cdfid, varid, MIvalid_min, NC_DOUBLE, 
-                       &(icvp->var_vmin));
-      if (status==MI_ERROR) 
-         icvp->var_vmin=MI_get_default_range(MIvalid_min, 
-                                             icvp->var_type, icvp->var_sign);
-   }
-   ncopts = oldncopts;
-
-   /* Handle possible rounding errors in having double valid_range for
-      float image type */
-   if (icvp->var_type == NC_FLOAT) {
-      icvp->var_vmax = (float) icvp->var_vmax;
-      icvp->var_vmin = (float) icvp->var_vmin;
-   }
+   icvp->var_vmin = vrange[0];
+   icvp->var_vmax = vrange[1];
 
    MI_RETURN(MI_NOERROR);
 }
@@ -999,41 +985,24 @@
 ---------------------------------------------------------------------------- */
 private double MI_get_default_range(char *what, nc_type datatype, int sign)
 {
-   double limit;
+   double range[2];
 
    MI_SAVE_ROUTINE_NAME("MI_get_default_range");
 
+   (void) miget_default_range(datatype, (sign == MI_PRIV_SIGNED), range);
+
    if (STRINGS_EQUAL(what, MIvalid_max)) {
-      switch (datatype) {
-      case NC_INT:
-         limit = (sign == MI_PRIV_SIGNED) ? INT_MAX : UINT_MAX; break;
-      case NC_SHORT:
-         limit = (sign == MI_PRIV_SIGNED) ? SHRT_MAX : USHRT_MAX; break;
-      case NC_BYTE:
-         limit = (sign == MI_PRIV_SIGNED) ? SCHAR_MAX : UCHAR_MAX; break;
-      default:
-         limit = MI_DEFAULT_MAX; break;
-      }
+      MI_RETURN(range[1]);
    }
    else if (STRINGS_EQUAL(what, MIvalid_min)) {
-      switch (datatype) {
-      case NC_INT:
-         limit = (sign == MI_PRIV_SIGNED) ? INT_MIN : 0; break;
-      case NC_SHORT:
-         limit = (sign == MI_PRIV_SIGNED) ? SHRT_MIN : 0; break;
-      case NC_BYTE:
-         limit = (sign == MI_PRIV_SIGNED) ? SCHAR_MIN : 0; break;
-      default:
-         limit = MI_DEFAULT_MIN; break;
-      }
+      MI_RETURN(range[0]);
    }
    else {
       ncopts = NC_VERBOSE | NC_FATAL;
       MI_LOG_PKG_ERROR2(-1,"MINC bug - this line should never be printed");
-      limit = MI_DEFAULT_MIN;
    }
 
-   MI_RETURN(limit);
+   MI_RETURN(MI_DEFAULT_MIN);
 }
 
 /* ----------------------------- MNI Header -----------------------------------
--- a/libsrc/minc.h
+++ b/libsrc/minc.h
@@ -19,7 +19,15 @@
 @CREATED    : July 24, 1992. (Peter Neelin, Montreal Neurological Institute)
 @MODIFIED   : 
  * $Log: minc.h,v $
- * Revision 6.5  2001-08-16 13:32:18  neelin
+ * Revision 6.6  2001-08-16 16:41:31  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.5  2001/08/16 13:32:18  neelin
  * Partial fix for valid_range of different type from image (problems
  * arising from double to float conversion/rounding). NOT COMPLETE.
  *
@@ -93,7 +101,7 @@
               make no representations about the suitability of this
               software for any purpose.  It is provided "as is" without
               express or implied warranty.
-@RCSID      : $Header: /private-cvsroot/minc/libsrc/minc.h,v 6.5 2001-08-16 13:32:18 neelin Exp $ MINC (MNI)
+@RCSID      : $Header: /private-cvsroot/minc/libsrc/minc.h,v 6.6 2001-08-16 16:41:31 neelin Exp $ MINC (MNI)
 ---------------------------------------------------------------------------- */
 
 #include <netcdf.h>
@@ -446,8 +454,8 @@
 /* From minc_convenience.c */
 public int miget_datatype(int cdfid, int imgid, 
                           nc_type *datatype, int *is_signed);
-public void miget_default_range(nc_type datatype, int is_signed, 
-                                double default_range[]);
+public int miget_default_range(nc_type datatype, int is_signed, 
+                               double default_range[]);
 public int miget_valid_range(int cdfid, int imgid, double valid_range[]);
 public int miset_valid_range(int cdfid, int imgid, double valid_range[]);
 public int miattput_pointer(int cdfid, int varid, char *name, int ptrvarid);
--- a/libsrc/minc_convenience.c
+++ b/libsrc/minc_convenience.c
@@ -3,6 +3,10 @@
 @DESCRIPTION: File of convenience functions following the minc standard.
 @METHOD     : Routines included in this file :
               public :
+                 miget_datatype
+                 miget_default_range
+                 miget_valid_range
+                 miset_valid_range
                  miattput_pointer
                  miattget_pointer
                  miadd_child
@@ -21,7 +25,15 @@
 @CREATED    : July 27, 1992. (Peter Neelin, Montreal Neurological Institute)
 @MODIFIED   : 
  * $Log: minc_convenience.c,v $
- * Revision 6.3  2001-08-16 13:32:18  neelin
+ * Revision 6.4  2001-08-16 16:41:32  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.3  2001/08/16 13:32:18  neelin
  * Partial fix for valid_range of different type from image (problems
  * arising from double to float conversion/rounding). NOT COMPLETE.
  *
@@ -71,7 +83,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/minc_convenience.c,v 6.3 2001-08-16 13:32:18 neelin Exp $ MINC (MNI)";
+static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/minc_convenience.c,v 6.4 2001-08-16 16:41:32 neelin Exp $ MINC (MNI)";
 #endif
 
 #include <type_limits.h>
@@ -116,9 +128,11 @@
    int old_ncopts;
    char attstr[MI_MAX_ATTSTR_LEN];
 
+   MI_SAVE_ROUTINE_NAME("miget_datatype");
+
    /* Get the type information for the variable */
    if (ncvarinq(cdfid, imgid, NULL, datatype, NULL, NULL, NULL) == MI_ERROR)
-      return MI_ERROR;
+      MI_RETURN(MI_ERROR);
 
    /* Save the ncopts value */
    old_ncopts = ncopts;
@@ -142,7 +156,7 @@
    /* Restore ncopts */
    ncopts = old_ncopts;
 
-   return MI_NOERROR;
+   MI_RETURN(MI_NOERROR);
 }
 
 /* ----------------------------- MNI Header -----------------------------------
@@ -150,7 +164,7 @@
 @INPUT      : datatype
               is_signed - TRUE if type is signed
 @OUTPUT     : default_range - array containing default range for variable
-@RETURNS    : MI_ERROR when an error occurs.
+@RETURNS    : MI_NOERROR
 @DESCRIPTION: Gets the default range for a data type.
 @METHOD     : 
 @GLOBALS    : 
@@ -158,9 +172,11 @@
 @CREATED    : August 15, 2001
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void miget_default_range(nc_type datatype, int is_signed, 
-                                double default_range[])
+public int miget_default_range(nc_type datatype, int is_signed, 
+                               double default_range[])
 {
+   MI_SAVE_ROUTINE_NAME("miget_default_range");
+
    switch (datatype) {
    case NC_INT:
       default_range[0] = (is_signed) ? INT_MIN : 0;
@@ -187,6 +203,8 @@
       default_range[1]= MI_DEFAULT_MAX;
       break;
    }
+
+   MI_RETURN(MI_NOERROR);
 }
 
 /* ----------------------------- MNI Header -----------------------------------
@@ -215,9 +233,11 @@
    int is_signed;
    double temp;
 
+   MI_SAVE_ROUTINE_NAME("miget_valid_range");
+
    /* Get the type information for the variable */
    if (miget_datatype(cdfid, imgid, &datatype, &is_signed) == MI_ERROR)
-      return MI_ERROR;
+      MI_RETURN(MI_ERROR);
 
    /* Save the ncopts value */
    old_ncopts = ncopts;
@@ -231,7 +251,7 @@
    if ((status==MI_ERROR) || (length!=2)) {
 
       /* Get the default range for the type */
-      miget_default_range(datatype, is_signed, valid_range);
+      (void) miget_default_range(datatype, is_signed, valid_range);
 
       /* Try to read the valid max */
       (void) miattget1(cdfid, imgid, MIvalid_max, NC_DOUBLE, &valid_range[1]);
@@ -272,7 +292,7 @@
       break;
    }
 
-   return MI_NOERROR;
+   MI_RETURN(MI_NOERROR);
 }
 
 /* ----------------------------- MNI Header -----------------------------------
@@ -306,9 +326,11 @@
    int sival[2];
    float fval[2];
 
+   MI_SAVE_ROUTINE_NAME("miset_valid_range");
+
    /* Get the type information for the variable */
    if (miget_datatype(cdfid, imgid, &datatype, &is_signed) == MI_ERROR)
-      return MI_ERROR;
+      MI_RETURN(MI_ERROR);
 
    /* Cast to the appropriate type and save */
    attname = MIvalid_range;
@@ -359,7 +381,7 @@
       break;
    }
 
-   return status;
+   MI_RETURN(status);
 
 }
 
--- a/progs/Proglib/voxel_loop.c
+++ b/progs/Proglib/voxel_loop.c
@@ -7,7 +7,15 @@
 @CREATED    : January 10, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: voxel_loop.c,v $
- * Revision 6.5  2001-08-16 13:32:27  neelin
+ * Revision 6.6  2001-08-16 16:41:32  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.5  2001/08/16 13:32:27  neelin
  * Partial fix for valid_range of different type from image (problems
  * arising from double to float conversion/rounding). NOT COMPLETE.
  *
@@ -86,7 +94,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/Proglib/Attic/voxel_loop.c,v 6.5 2001-08-16 13:32:27 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/Proglib/Attic/voxel_loop.c,v 6.6 2001-08-16 16:41:32 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -1008,8 +1016,7 @@
       ncopts = NC_OPTS_VAL;
       valid_range[0] = 0;
       valid_range[1] = 1;
-      (void) ncattput(outmincid, outimgid, MIvalid_range, NC_DOUBLE, 2,
-                      (void *) valid_range);
+      (void) miset_valid_range(outmincid, outimgid, valid_range);
    }
    else if (loop_options->datatype != MI_ORIGINAL_TYPE) {
       if (loop_options->is_signed)
@@ -1017,8 +1024,8 @@
       else
          (void) miattputstr(outmincid, outimgid, MIsigntype, MI_UNSIGNED);
       if ((loop_options->valid_range[1] > loop_options->valid_range[0])) {
-         (void) ncattput(outmincid, outimgid, MIvalid_range, NC_DOUBLE, 2,
-                         (void *) loop_options->valid_range);
+         (void) miset_valid_range(outmincid, outimgid, 
+                                  loop_options->valid_range);
       }
       else {
          ncopts = 0;
@@ -1549,8 +1556,8 @@
             valid_range[1] = (float) valid_range[1];
          }
 
-         (void) ncattput(outmincid, imgid, MIvalid_range, NC_DOUBLE, 2,
-                         (void *) valid_range);
+         (void) miset_valid_range(outmincid, imgid, valid_range);
+
       }
    }
 
--- a/progs/minccalc/gram.c
+++ b/progs/minccalc/gram.c
@@ -406,7 +406,7 @@
     47
 };
 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
-#line 3 "/usr/local/share/bison.simple"
+#line 3 "//usr/lib/bison.simple"
 /* This file comes from bison-1.28.  */
 
 /* Skeleton output parser for bison,
@@ -620,7 +620,7 @@
 #endif
 #endif
 
-#line 217 "/usr/local/share/bison.simple"
+#line 217 "//usr/lib/bison.simple"
 
 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
    into yyparse.  The argument should have type void *.
@@ -1390,7 +1390,7 @@
     break;}
 }
    /* the action file gets copied in in place of this dollarsign */
-#line 543 "/usr/local/share/bison.simple"
+#line 543 "//usr/lib/bison.simple"
 
   yyvsp -= yylen;
   yyssp -= yylen;
--- a/progs/mincconcat/mincconcat.c
+++ b/progs/mincconcat/mincconcat.c
@@ -11,7 +11,15 @@
 @CREATED    : March 7, 1995 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincconcat.c,v $
- * Revision 6.6  2001-08-16 13:32:33  neelin
+ * Revision 6.7  2001-08-16 16:41:33  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.6  2001/08/16 13:32:33  neelin
  * Partial fix for valid_range of different type from image (problems
  * arising from double to float conversion/rounding). NOT COMPLETE.
  *
@@ -79,7 +87,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincconcat/mincconcat.c,v 6.6 2001-08-16 13:32:33 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincconcat/mincconcat.c,v 6.7 2001-08-16 16:41:33 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -240,16 +248,9 @@
       valid_range[0] = concat_info->global_minimum;
       valid_range[1] = concat_info->global_maximum;
 
-      /* Force truncation of valid_range to match float image */
-      if ((ncvarinq(concat_info->output_mincid, imgid, 
-                    NULL, &file_datatype, NULL, NULL, NULL) != MI_ERROR) && 
-          (file_datatype == NC_FLOAT)) {
-         valid_range[0] = (float) valid_range[0];
-         valid_range[1] = (float) valid_range[1];
-      }
+      (void) miset_valid_range(concat_info->output_mincid, imgid,  
+                               valid_range);
 
-      (void) ncattput(concat_info->output_mincid, imgid, MIvalid_range, 
-                      NC_DOUBLE, 2, (void *) valid_range);
    }
    (void) miclose(concat_info->output_mincid);
    (void) miicv_free(concat_info->output_icvid);
@@ -1297,8 +1298,8 @@
       ncopts = NC_OPTS_VAL;
       valid_range[0] = 0;
       valid_range[1] = 1;
-      (void) ncattput(outmincid, outimgid, MIvalid_range, NC_DOUBLE, 2,
-                      (void *) valid_range);
+      (void) miset_valid_range(outmincid, outimgid,  
+                               valid_range);
    }
    if (concat_info->output_datatype != MI_ORIGINAL_TYPE) {
       if (concat_info->output_is_signed)
@@ -1307,8 +1308,8 @@
          (void) miattputstr(outmincid, outimgid, MIsigntype, MI_UNSIGNED);
       if (concat_info->output_valid_range[1] > 
           concat_info->output_valid_range[0]) {
-         (void) ncattput(outmincid, outimgid, MIvalid_range, NC_DOUBLE, 2,
-                         (void *) concat_info->output_valid_range);
+         (void) miset_valid_range(outmincid, outimgid,
+                                  concat_info->output_valid_range);
       }
       else {
          ncopts = 0;
--- a/progs/mincexample/mincexample1.c
+++ b/progs/mincexample/mincexample1.c
@@ -10,7 +10,15 @@
 @CREATED    : August 24, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincexample1.c,v $
- * Revision 6.2  2001-04-17 18:40:18  neelin
+ * Revision 6.3  2001-08-16 16:41:34  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.2  2001/04/17 18:40:18  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.
@@ -60,7 +68,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample1.c,v 6.2 2001-04-17 18:40:18 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample1.c,v 6.3 2001-08-16 16:41:34 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -540,7 +548,7 @@
       ncopts = NC_OPTS_VAL;
    }
    (void) miattputstr(mincid, imgid, MIsigntype, MI_UNSIGNED);
-   (void) ncattput(mincid, imgid, MIvalid_range, NC_DOUBLE, 2, valid_range);
+   (void) miset_valid_range(mincid, imgid, valid_range);
 
    /* Create the image max and min variables */
    maxid = micreate_std_variable(mincid, MIimagemax, NC_DOUBLE, 0, NULL);
--- a/progs/mincexample/mincexample2.c
+++ b/progs/mincexample/mincexample2.c
@@ -12,7 +12,15 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincexample2.c,v $
- * Revision 6.2  2001-04-17 18:40:19  neelin
+ * Revision 6.3  2001-08-16 16:41:34  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.2  2001/04/17 18:40:19  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.
@@ -48,7 +56,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample2.c,v 6.2 2001-04-17 18:40:19 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample2.c,v 6.3 2001-08-16 16:41:34 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -625,7 +633,7 @@
       ncopts = NC_OPTS_VAL;
    }
    (void) miattputstr(mincid, imgid, MIsigntype, MI_UNSIGNED);
-   (void) ncattput(mincid, imgid, MIvalid_range, NC_DOUBLE, 2, valid_range);
+   (void) miset_valid_range(mincid, imgid, valid_range);
 
    /* Create the image max and min variables (varying over slices) */
    maxid = micreate_std_variable(mincid, MIimagemax, NC_DOUBLE, 1, dim);
--- a/progs/mincextract/mincextract.c
+++ b/progs/mincextract/mincextract.c
@@ -10,7 +10,15 @@
 @CREATED    : June 10, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincextract.c,v $
- * Revision 6.2  2001-04-17 18:40:19  neelin
+ * Revision 6.3  2001-08-16 16:41:35  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.2  2001/04/17 18:40:19  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.
@@ -74,7 +82,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincextract/mincextract.c,v 6.2 2001-04-17 18:40:19 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincextract/mincextract.c,v 6.3 2001-08-16 16:41:35 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -107,24 +115,6 @@
 static nc_type nc_type_list[8] = {
    NC_DOUBLE, NC_BYTE, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE, NC_DOUBLE
 };
-static double default_max[][2] = {
-   0.0, 0.0,
-   UCHAR_MAX, SCHAR_MAX,
-   0.0, 0.0,
-   USHRT_MAX, SHRT_MAX,
-   UINT_MAX, INT_MAX,
-   1.0, 1.0,
-   1.0, 1.0
-};
-static double default_min[][2] = {
-   0.0, 0.0,
-   0.0, SCHAR_MIN,
-   0.0, 0.0,
-   0.0, SHRT_MIN,
-   0.0, INT_MIN,
-   0.0, 0.0,
-   0.0, 0.0
-};
 
 /* Function declarations */
 public int get_arg_vector(char *dst, char *key, char *nextArg);
@@ -271,7 +261,8 @@
 
    /* Inquire about the image variable */
    imgid = ncvarid(mincid, MIimage);
-   (void) ncvarinq(mincid, imgid, NULL, &datatype, &ndims, dims, NULL);
+   (void) ncvarinq(mincid, imgid, NULL, NULL, &ndims, dims, NULL);
+   (void) miget_datatype(mincid, imgid, &datatype, &is_signed);
 
    /* Check if arguments set */
 
@@ -292,19 +283,6 @@
    if (arg_odatatype == TYPE_FILE) output_datatype = datatype;
 
    /* Get output sign */ 
-   ncopts = 0;
-   if (miattgetstr(mincid, imgid, MIsigntype, MI_MAX_ATTSTR_LEN, 
-                   the_sign) != NULL) {
-      if (strcmp(the_sign, MI_SIGNED) == 0)
-         is_signed = TRUE;
-      else if (strcmp(the_sign, MI_UNSIGNED) == 0)
-         is_signed = FALSE;
-      else
-         is_signed = (datatype != NC_BYTE);
-   }
-   else
-      is_signed = (datatype != NC_BYTE);
-   ncopts = NC_VERBOSE | NC_FATAL;
    if (output_signed == INT_MAX) {
       if (arg_odatatype == TYPE_FILE)
          output_signed = is_signed;
@@ -315,21 +293,11 @@
    /* Get output range */
    if (valid_range[0] == DBL_MAX) {
       if (arg_odatatype == TYPE_FILE) {
-         ncopts = 0;
-         if ((miattget(mincid, imgid, MIvalid_range, NC_DOUBLE, 2, 
-                       valid_range, &length) == MI_ERROR) || (length!=2)) {
-            if (miattget1(mincid, imgid, MIvalid_max, NC_DOUBLE, 
-                          &valid_range[1]) == MI_ERROR)
-               valid_range[1] = default_max[datatype][is_signed]; 
-            if (miattget1(mincid, imgid, MIvalid_min, NC_DOUBLE, 
-                          &valid_range[0]) == MI_ERROR)
-               valid_range[0] = default_min[datatype][is_signed]; 
-         }
-         ncopts = NC_VERBOSE | NC_FATAL;
+         (void) miget_valid_range(mincid, imgid, valid_range);
       }
       else {
-         valid_range[0] = default_min[output_datatype][output_signed];
-         valid_range[1] = default_max[output_datatype][output_signed];
+         (void) miget_default_range(output_datatype, output_signed, 
+                                    valid_range);
       }
    }
    if (valid_range[0] > valid_range[1]) {
--- a/progs/mincinfo/mincinfo.c
+++ b/progs/mincinfo/mincinfo.c
@@ -10,7 +10,15 @@
 @CREATED    : May 19, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincinfo.c,v $
- * Revision 6.2  2000-04-25 18:12:05  neelin
+ * Revision 6.3  2001-08-16 16:41:35  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.2  2000/04/25 18:12:05  neelin
  * Added modified version of patch from Steve Robbins to allow use on
  * multiple input files.
  *
@@ -67,7 +75,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincinfo/mincinfo.c,v 6.2 2000-04-25 18:12:05 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincinfo/mincinfo.c,v 6.3 2001-08-16 16:41:35 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -93,24 +101,6 @@
 char *type_names[] = {
    NULL, "byte", "char", "short", "long", "float", "double"
 };
-double default_min[][2] = {
-   0.0, 0.0,
-   0.0, SCHAR_MIN,
-   0.0, 0.0,
-   0.0, SHRT_MIN,
-   0.0, LONG_MIN,
-   0.0, 0.0,
-   0.0, 0.0,
-};
-double default_max[][2] = {
-   0.0, 0.0,
-   UCHAR_MAX, SCHAR_MAX,
-   0.0, 0.0,
-   USHRT_MAX, SHRT_MAX,
-   ULONG_MAX, LONG_MAX,
-   1.0, 1.0,
-   1.0, 1.0
-};
 
 /* Types */
 typedef enum  {
@@ -543,7 +533,7 @@
    double valid_range[2];
    char sign_type[MI_MAX_ATTSTR_LEN];
    int sign_index;
-   int att_length;
+   int is_signed;
    long length;
    int idim;
    char name[MAX_NC_NAME];
@@ -552,34 +542,12 @@
 
    /* Get information about variable */
    RTN_ERR(imgid = ncvarid(mincid, MIimage));
-   RTN_ERR(ncvarinq(mincid, imgid, NULL, &datatype, &ndims, dim, NULL));
-
-   oldncopts = ncopts;
-   ncopts = 0;
+   RTN_ERR(ncvarinq(mincid, imgid, NULL, NULL, &ndims, dim, NULL));
+   RTN_ERR(miget_datatype(mincid, imgid, &datatype, &is_signed));
+   RTN_ERR(miget_valid_range(mincid, imgid, valid_range));
 
-   /* Look for signtype */
-   if ((miattgetstr(mincid, imgid, MIsigntype, MI_MAX_ATTSTR_LEN, sign_type)
-                  == NULL) || ((strcmp(sign_type, MI_UNSIGNED)!=0) && 
-                               (strcmp(sign_type, MI_SIGNED)!=0))) {
-      if (datatype == NC_BYTE)
-         (void) strcpy(sign_type, MI_UNSIGNED);
-      else
-         (void) strcpy(sign_type, MI_SIGNED);
-   }
-   sign_index = (strcmp(sign_type, MI_UNSIGNED) == 0) ? 0 : 1;
-
-   /* Get valid range */
-   if ((miattget(mincid, imgid, MIvalid_range, NC_DOUBLE, 2, valid_range,
-                 &att_length) == MI_ERROR) || (att_length != 2)) {
-      if (miattget1(mincid, imgid, MIvalid_min, NC_DOUBLE, 
-                    &valid_range[0]) == MI_ERROR)
-         valid_range[0] = default_min[datatype][sign_index];
-      if (miattget1(mincid, imgid, MIvalid_max, NC_DOUBLE, 
-                    &valid_range[1]) == MI_ERROR)
-         valid_range[1] = default_max[datatype][sign_index];
-   }
-
-   ncopts = oldncopts;
+   /* Get sign index;
+   sign_index = (is_signed ? 1 : 0);
 
    /* Write out image info line */
    (void) printf("file: %s\n", filename);
--- a/progs/mincreshape/mincreshape.c
+++ b/progs/mincreshape/mincreshape.c
@@ -13,7 +13,15 @@
 @CREATED    : March 10, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincreshape.c,v $
- * Revision 6.5  2001-04-24 13:38:45  neelin
+ * Revision 6.6  2001-08-16 16:41:36  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.5  2001/04/24 13:38:45  neelin
  * Replaced NC_NAT with MI_ORIGINAL_TYPE.
  *
  * Revision 6.4  2001/04/17 18:40:24  neelin
@@ -74,7 +82,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincreshape/mincreshape.c,v 6.5 2001-04-24 13:38:45 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincreshape/mincreshape.c,v 6.6 2001-08-16 16:41:36 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -827,6 +835,7 @@
    double vrange[2];
    char string[MI_MAX_ATTSTR_LEN];
    int length;
+   int file_is_signed;
 
    /* Get the image variable id */
    imgid = ncvarid(mincid, MIimage);
@@ -836,55 +845,23 @@
       if (*is_signed == INT_MIN) {
          *is_signed = ((*datatype == NC_BYTE) ? FALSE : TRUE);
       }
+      if (valid_range[0] == DBL_MAX) {
+         (void) miget_default_range(*datatype, *is_signed, valid_range);
+      }
       return;
    }
 
    /* Get data type */
-   (void) ncvarinq(mincid, imgid, NULL, datatype, NULL, NULL, NULL);
+   (void) miget_datatype(mincid, imgid, datatype, &file_is_signed);
 
    /* Look for sign if needed */
    if (*is_signed == INT_MIN) {
-      ncopts = 0;
-      if (miattgetstr(mincid, imgid, MIsigntype, sizeof(string), string) 
-          != NULL) {
-         if (strcmp(string, MI_SIGNED) == 0)
-            *is_signed = TRUE;
-         else if (strcmp(string, MI_UNSIGNED) == 0)
-            *is_signed = FALSE;
-      }
-      ncopts = NCOPTS_DEFAULT;
-      if (*is_signed == INT_MIN) {
-         *is_signed = ((*datatype == NC_BYTE) ? FALSE : TRUE);
-      }
+      *is_signed = file_is_signed;
    }
 
    /* Look for valid range if needed */
    if (valid_range[0] == DBL_MAX) {
-      ncopts = 0;
-      status=miattget(mincid, imgid, MIvalid_range, 
-                      NC_DOUBLE, 2, vrange, &length);
-      if ((status!=MI_ERROR) && (length==2)) {
-         if (vrange[1] > vrange[0]) {
-            valid_range[0] = vrange[0];
-            valid_range[1] = vrange[1];
-         }
-         else {
-            valid_range[0] = vrange[1];
-            valid_range[1] = vrange[0];
-         }
-      }
-      else {
-         status=miattget1(mincid, imgid, MIvalid_max, 
-                          NC_DOUBLE, &vrange[1]);
-         if (status!=MI_ERROR) valid_range[1] = vrange[1];
-  
-         status=miattget1(mincid, imgid, MIvalid_min, 
-                          NC_DOUBLE, &vrange[0]);
-         if (status!=MI_ERROR)
-         if (status!=MI_ERROR) valid_range[1] = vrange[1];
-
-      }
-      ncopts = NCOPTS_DEFAULT;
+      (void) miget_valid_range(mincid, imgid, valid_range);
    }
 
    return;
@@ -1359,7 +1336,7 @@
                           ncvarid(reshape_info->inmincid, MIimage),
                           mincid, imgid);
    (void) miattputstr(mincid, imgid, MIsigntype, signtype);
-   (void) ncattput(mincid, imgid, MIvalid_range, NC_DOUBLE, 2, valid_range);
+   (void) miset_valid_range(mincid, imgid, valid_range);
    (void) miattputstr(mincid, imgid, MIcomplete, MI_FALSE);
 
    /* Create the imagemax/min variables */
--- a/progs/minctoraw/minctoraw.c
+++ b/progs/minctoraw/minctoraw.c
@@ -10,7 +10,15 @@
 @CREATED    : February 11, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: minctoraw.c,v $
- * Revision 6.5  2001-08-16 16:18:47  neelin
+ * Revision 6.6  2001-08-16 16:41:36  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.5  2001/08/16 16:18:47  neelin
  * Fixed typo for compile
  *
  * Revision 6.4  2001/08/16 16:17:22  neelin
@@ -68,7 +76,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/minctoraw/minctoraw.c,v 6.5 2001-08-16 16:18:47 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/minctoraw/minctoraw.c,v 6.6 2001-08-16 16:41:36 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -86,24 +94,6 @@
 #  define FALSE 0
 #endif
 #define BOOLEAN_DEFAULT -1
-static double default_max[][2] = {
-   0.0, 0.0,
-   UCHAR_MAX, SCHAR_MAX,
-   0.0, 0.0,
-   USHRT_MAX, SHRT_MAX,
-   ULONG_MAX, LONG_MAX,
-   1.0, 1.0,
-   1.0, 1.0
-};
-static double default_min[][2] = {
-   0.0, 0.0,
-   0.0, SCHAR_MIN,
-   0.0, 0.0,
-   0.0, SHRT_MIN,
-   0.0, LONG_MIN,
-   0.0, 0.0,
-   0.0, 0.0
-};
 
 /* Variables used for argument parsing */
 nc_type output_datatype = INT_MAX;
@@ -175,7 +165,8 @@
 
    /* Inquire about the image variable */
    imgid = ncvarid(mincid, MIimage);
-   (void) ncvarinq(mincid, imgid, NULL, &datatype, &ndims, dims, NULL);
+   (void) ncvarinq(mincid, imgid, NULL, NULL, &ndims, dims, NULL);
+   (void)miget_datatype(mincid, imgid, &datatype, &is_signed);
 
    /* Check if arguments set */
 
@@ -183,19 +174,6 @@
    if (output_datatype == INT_MAX) output_datatype = datatype;
 
    /* Get output sign */ 
-   ncopts = 0;
-   if (miattgetstr(mincid, imgid, MIsigntype, MI_MAX_ATTSTR_LEN, 
-                   the_sign) != NULL) {
-      if (strcmp(the_sign, MI_SIGNED) == 0)
-         is_signed = TRUE;
-      else if (strcmp(the_sign, MI_UNSIGNED) == 0)
-         is_signed = FALSE;
-      else
-         is_signed = (datatype != NC_BYTE);
-   }
-   else
-      is_signed = (datatype != NC_BYTE);
-   ncopts = NC_VERBOSE | NC_FATAL;
    if (output_signed == INT_MAX) {
       if (output_datatype == datatype)
          output_signed = is_signed;
@@ -206,21 +184,11 @@
    /* Get output range */
    if (valid_range[0] == DBL_MAX) {
       if ((output_datatype == datatype) && (output_signed == is_signed)) {
-         ncopts = 0;
-         if ((miattget(mincid, imgid, MIvalid_range, NC_DOUBLE, 2, 
-                       valid_range, &length) == MI_ERROR) || (length!=2)) {
-            if (miattget1(mincid, imgid, MIvalid_max, NC_DOUBLE, 
-                          &valid_range[1]) == MI_ERROR)
-               valid_range[1] = default_max[datatype][is_signed]; 
-            if (miattget1(mincid, imgid, MIvalid_min, NC_DOUBLE, 
-                          &valid_range[0]) == MI_ERROR)
-               valid_range[0] = default_min[datatype][is_signed]; 
-         }
-         ncopts = NC_VERBOSE | NC_FATAL;
+         (void) miget_valid_range(mincid, imgid, valid_range);
       }
       else {
-         valid_range[0] = default_min[output_datatype][output_signed];
-         valid_range[1] = default_max[output_datatype][output_signed];
+         (void) miget_default_range(output_datatype, output_signed, 
+                                    valid_range);
       }
    }
    if (valid_range[0] > valid_range[1]) {
--- a/progs/rawtominc/rawtominc.c
+++ b/progs/rawtominc/rawtominc.c
@@ -11,7 +11,15 @@
 @CREATED    : September 25, 1992 (Peter Neelin)
 @MODIFIED   : 
  * $Log: rawtominc.c,v $
- * Revision 6.5  2001-04-24 13:38:46  neelin
+ * Revision 6.6  2001-08-16 16:41:37  neelin
+ * Added library functions to handle reading of datatype, sign and valid range,
+ * plus writing of valid range and setting of default ranges. These functions
+ * properly handle differences between valid_range type and image type. Such
+ * difference can cause valid data to appear as invalid when double to float
+ * conversion causes rounding in the wrong direction (out of range).
+ * Modified voxel_loop, volume_io and programs to use these functions.
+ *
+ * Revision 6.5  2001/04/24 13:38:46  neelin
  * Replaced NC_NAT with MI_ORIGINAL_TYPE.
  *
  * Revision 6.4  2001/04/17 18:40:25  neelin
@@ -110,7 +118,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/rawtominc/rawtominc.c,v 6.5 2001-04-24 13:38:46 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/rawtominc/rawtominc.c,v 6.6 2001-08-16 16:41:37 neelin Exp $";
 #endif
 
 #include <stdlib.h>
@@ -606,7 +614,7 @@
    (void) miattputstr(cdfid, imgid, MIcomplete, MI_FALSE);
    (void) miattputstr(cdfid, imgid, MIsigntype, osign);
    if (ovrange_set) 
-      (void) ncattput(cdfid, imgid, MIvalid_range, NC_DOUBLE, 2, ovalid_range);
+      (void) miset_valid_range(cdfid, imgid, ovalid_range);
    if (do_minmax || do_real_range) {
       maxid = micreate_std_variable(cdfid, MIimagemax, 
                                     NC_DOUBLE, ndims-image_dims, dim);
@@ -777,7 +785,7 @@
 
    /* Write the valid max and min */
    if (do_vrange) {
-      (void) ncattput(cdfid, imgid, MIvalid_range, NC_DOUBLE, 2, ovalid_range);
+      (void) miset_valid_range(cdfid, imgid, ovalid_range);
    }
 
    /* Close the file */
--- a/volume_io/Volumes/input_mnc.c
+++ b/volume_io/Volumes/input_mnc.c
@@ -16,7 +16,7 @@
 #include  <minc.h>
 
 #ifndef lint
-static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/input_mnc.c,v 1.62 2001-08-16 13:32:43 neelin Exp $";
+static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/input_mnc.c,v 1.63 2001-08-16 16:41:37 neelin Exp $";
 #endif
 
 #define  INVALID_AXIS   -1
@@ -107,7 +107,7 @@
     int                 i, slab_size, length, prev_sizes[MAX_VAR_DIMS];
     nc_type             prev_nc_type;
     BOOLEAN             different;
-    BOOLEAN             min_voxel_found, max_voxel_found, range_specified;
+    BOOLEAN             range_specified;
     double              valid_range[2], temp;
     long                long_size;
     BOOLEAN             converted_sign, space_type_consensus;
@@ -121,7 +121,6 @@
     double              file_separations[MAX_VAR_DIMS];
     Real                volume_separations[MAX_VAR_DIMS];
     Real                volume_starts[MAX_VAR_DIMS];
-    Real                default_voxel_min, default_voxel_max;
     Real                voxel_zero;
     double              start_position[MAX_VAR_DIMS];
     double              dir_cosines[MAX_VAR_DIMS][MI_NUM_SPACE_DIMS];
@@ -424,70 +423,27 @@
     get_volume_voxel_range( volume, &valid_range[0], &valid_range[1] );
     range_specified = (valid_range[0] < valid_range[1]);
 
-    max_voxel_found = FALSE;
-    min_voxel_found = FALSE;
-
     valid_range[0] = 0.0;
     valid_range[1] = 0.0;
 
     if( file->converting_to_colour )
     {
-        min_voxel_found = TRUE;
-        max_voxel_found = TRUE;
         valid_range[0] = 0.0;
         valid_range[1] = 2.0 * (double) (1ul << 31ul) - 1.0;
         set_volume_voxel_range( volume, valid_range[0], valid_range[1] );
     }
     else if( no_volume_data_type )
     {
-        if( miattget( file->cdfid, file->img_var, MIvalid_range, NC_DOUBLE,
-                         2, (void *) valid_range, &length ) == MI_ERROR ||
-            length != 2 )
-        {
-            if( miattget1( file->cdfid, file->img_var, MIvalid_min, NC_DOUBLE,
-                           (void *) &valid_range[0] ) != MI_ERROR )
-            {
-                min_voxel_found = TRUE;
-            }
-            if( miattget1( file->cdfid, file->img_var, MIvalid_max, NC_DOUBLE,
-                           (void *) &valid_range[1] ) != MI_ERROR )
-            {
-                max_voxel_found = TRUE;
-            }
-        }
-        else
-        {
-            if( valid_range[0] > valid_range[1] )
-            {
-                temp = valid_range[0];
-                valid_range[0] = valid_range[1];
-                valid_range[1] = temp;
-            }
-            min_voxel_found = TRUE;
-            max_voxel_found = TRUE;
-        }
-
-        /* Check for float image and cast the valid range to float to
-           handle potential float/double rounding errors */
-        if ( file_datatype == NC_FLOAT )
-        {
-            valid_range[0] = (float) valid_range[0];
-            valid_range[1] = (float) valid_range[1];
+        if (miget_valid_range( file->cdfid, file->img_var, 
+                               valid_range) == MI_ERROR) {
+           valid_range[0] = valid_range[1] = 0.0;
         }
     }
 
     if( !file->converting_to_colour &&
         (no_volume_data_type || !range_specified) )
     {
-        set_volume_voxel_range( volume, 0.0, 0.0 );
-        get_volume_voxel_range( volume, &default_voxel_min, &default_voxel_max);
-
-        if( min_voxel_found && max_voxel_found )
-            set_volume_voxel_range( volume, valid_range[0], valid_range[1] );
-        else if( min_voxel_found && !max_voxel_found )
-            set_volume_voxel_range( volume, valid_range[0], default_voxel_max );
-        else if( !min_voxel_found && max_voxel_found )
-            set_volume_voxel_range( volume, default_voxel_min, valid_range[0] );
+        set_volume_voxel_range( volume, valid_range[0], valid_range[1] );
     }
 
     if( !file->converting_to_colour )
--- a/volume_io/Volumes/output_mnc.c
+++ b/volume_io/Volumes/output_mnc.c
@@ -16,7 +16,7 @@
 #include  <minc.h>
 
 #ifndef lint
-static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/output_mnc.c,v 1.57 2001-08-16 13:32:43 neelin Exp $";
+static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/Volumes/output_mnc.c,v 1.58 2001-08-16 16:41:38 neelin Exp $";
 #endif
 
 #define  INVALID_AXIS   -1
@@ -426,16 +426,8 @@
         valid_range[0] = file_voxel_min;
         valid_range[1] = file_voxel_max;
 
-        /* Cast valid_range to float if image type is float to
-           be consistent with double/float rounding of image data */
-        if ( file_nc_data_type == NC_FLOAT ) 
-        {
-            valid_range[0] = (float) valid_range[0];
-            valid_range[1] = (float) valid_range[1];
-        }
+        (void) miset_valid_range( file->cdfid, file->img_var_id, valid_range);
 
-        (void) ncattput( file->cdfid, file->img_var_id, MIvalid_range,
-                         NC_DOUBLE, 2, (void *) valid_range );
     }
 
     file->image_range[0] = options->global_image_range[0];