Mercurial > hg > minc-tools
changeset 60:38507ce3d203
*** empty log message ***
author | david <david> |
---|---|
date | Mon, 11 Jan 1993 11:20:17 +0000 |
parents | 0dc1ca86ed1b |
children | 4bdb79d75e0a |
files | volume_io/Prog_utils/alloc.c volume_io/Prog_utils/alloc_check.c volume_io/Prog_utils/files.c volume_io/Prog_utils/time.c volume_io/Volumes/input_volume.c |
diffstat | 5 files changed, 569 insertions(+), 583 deletions(-) [+] |
line wrap: on
line diff
--- a/volume_io/Prog_utils/alloc.c +++ b/volume_io/Prog_utils/alloc.c @@ -8,6 +8,10 @@ typedef char *alloc_ptr; #endif +private void record_alloc( int ); +private void record_realloc( int ); +private void record_free( void ); + /* ----------------------------- MNI Header ----------------------------------- @NAME : alloc_memory @INPUT : n_bytes @@ -21,12 +25,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status alloc_memory( ptr, n_bytes ) - void **ptr; - int n_bytes; +public Status alloc_memory( + void **ptr, + int n_bytes ) { - void abort_if_allowed(); - void record_alloc(); Status status; status = OK; @@ -37,8 +39,7 @@ if( *ptr == (void *) 0 ) { - (void) printf( "alloc_memory: out of memory, %d bytes.\n", - n_bytes ); + print( "Error alloc_memory: out of memory, %d bytes.\n", n_bytes ); status = OUT_OF_MEMORY; abort_if_allowed(); } @@ -65,14 +66,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status realloc_memory( ptr, n_bytes ) - void **ptr; - int n_bytes; +public Status realloc_memory( + void **ptr, + int n_bytes ) { - void abort_if_allowed(); Status status; - Status free_memory(); - void record_realloc(); status = OK; @@ -82,8 +80,8 @@ if( *ptr == (void *) 0 ) { - (void) printf( "realloc_memory: out of memory, %d bytes.\n", - n_bytes ); + print( "Error realloc_memory: out of memory, %d bytes.\n", + n_bytes ); status = OUT_OF_MEMORY; abort_if_allowed(); } @@ -107,11 +105,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status free_memory( ptr ) - void **ptr; +public Status free_memory( void **ptr ) { - void record_free(); - record_free(); if( *ptr != (void *) 0 ) @@ -140,13 +135,13 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void abort_if_allowed() +public void abort_if_allowed( void ) { char ch; if( !ENV_EXISTS( "NO_ABORT" ) ) { - (void) printf( "Do you wish to abort (y/n): " ); + print( "Do you wish to abort (y/n): " ); do { ch = getchar(); @@ -168,7 +163,7 @@ private FILE *file; -private Boolean writing_alloc_debug() +private Boolean writing_alloc_debug( void ) { static Boolean first = TRUE; static Boolean writing = FALSE; @@ -191,8 +186,7 @@ return( writing ); } -private void record_alloc( n_bytes ) - int n_bytes; +private void record_alloc( int n_bytes ) { if( writing_alloc_debug() ) { @@ -201,8 +195,7 @@ } } -private void record_realloc( n_bytes ) - int n_bytes; +private void record_realloc( int n_bytes ) { if( writing_alloc_debug() ) { @@ -211,7 +204,7 @@ } } -private void record_free() +private void record_free( void ) { if( writing_alloc_debug() ) {
--- a/volume_io/Prog_utils/alloc_check.c +++ b/volume_io/Prog_utils/alloc_check.c @@ -1,7 +1,5 @@ -#include <def_string.h> #include <def_mni.h> -#include <def_files.h> #include <stdlib.h> /* ----------------------------- MNI Header ----------------------------------- @@ -24,14 +22,6 @@ #define MEMORY_DIFFERENCE 1000000 -static void update_total_memory(); -static int get_random_level(); -static Real get_random_0_to_1(); -static void output_entry(); -static Real current_seconds(); -static void get_date(); -void abort_if_allowed(); - typedef struct skip_struct { void *ptr; @@ -55,6 +45,11 @@ skip_struct *update[MAX_SKIP_LEVELS]; } update_struct; +private void update_total_memory( alloc_struct *, int ); +private int get_random_level( void ); +private void output_entry( FILE *, skip_struct * ); +private Boolean size_display_enabled( void ); + #ifdef sgi typedef size_t alloc_int; typedef void *alloc_ptr; @@ -80,8 +75,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private void initialize_alloc_list( alloc_list ) - alloc_struct *alloc_list; +private void initialize_alloc_list( + alloc_struct *alloc_list ) { int i; @@ -95,8 +90,8 @@ alloc_list->header->forward[i] = (skip_struct *) 0; } -private void check_initialized_alloc_list( alloc_list ) - alloc_struct *alloc_list; +private void check_initialized_alloc_list( + alloc_struct *alloc_list ) { static Boolean first = TRUE; @@ -122,10 +117,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private Boolean find_pointer_position( alloc_list, ptr, update ) - alloc_struct *alloc_list; - void *ptr; - update_struct *update; +private Boolean find_pointer_position( + alloc_struct *alloc_list, + void *ptr, + update_struct *update ) { int i; skip_struct *x; @@ -168,16 +163,14 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private void insert_ptr_in_alloc_list( alloc_list, update, ptr, n_bytes, - source_file, line_number, - time_of_alloc ) - alloc_struct *alloc_list; - update_struct *update; - void *ptr; - int n_bytes; - char source_file[]; - int line_number; - Real time_of_alloc; +private void insert_ptr_in_alloc_list( + alloc_struct *alloc_list, + update_struct *update, + void *ptr, + int n_bytes, + char source_file[], + int line_number, + Real time_of_alloc ) { int i, new_level; skip_struct *x; @@ -224,11 +217,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private Boolean check_overlap( update, ptr, n_bytes, entry ) - update_struct *update; - void *ptr; - int n_bytes; - skip_struct **entry; +private Boolean check_overlap( + alloc_struct *alloc_list, + update_struct *update, + void *ptr, + int n_bytes, + skip_struct **entry ) { Boolean overlap; @@ -236,7 +230,7 @@ *entry = update->update[0]; - if( *entry != (skip_struct *) 0 ) + if( *entry != alloc_list->header && *entry != (skip_struct *) 0 ) { if( (void *) ((char *) (*entry)->ptr + (*entry)->n_bytes) > ptr ) overlap = TRUE; @@ -270,13 +264,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private Boolean remove_ptr_from_alloc_list( alloc_list, ptr, source_file, - line_number, time_of_alloc ) - alloc_struct *alloc_list; - void *ptr; - char *source_file[]; - int *line_number; - Real *time_of_alloc; +private Boolean remove_ptr_from_alloc_list( + alloc_struct *alloc_list, + void *ptr, + char *source_file[], + int *line_number, + Real *time_of_alloc ) { int i; Boolean found; @@ -329,10 +322,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private int get_random_level() +private int get_random_level( void ) { int level; - Real get_random_0_to_1(); level = 1; @@ -343,8 +335,8 @@ } #ifdef NOT_NEEDED -private void delete_alloc_list( alloc_list ) - alloc_struct *alloc_list; +private void delete_alloc_list( + alloc_struct *alloc_list ) { skip_struct *ptr, *deleting; @@ -374,9 +366,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private void output_alloc_list( file, alloc_list ) - FILE *file; - alloc_struct *alloc_list; +private void output_alloc_list( + FILE *file, + alloc_struct *alloc_list ) { skip_struct *ptr; @@ -403,9 +395,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private void update_total_memory( alloc_list, n_bytes ) - alloc_struct *alloc_list; - int n_bytes; +private void update_total_memory( + alloc_struct *alloc_list, + int n_bytes ) { alloc_list->total_memory_allocated += n_bytes; @@ -415,8 +407,8 @@ { alloc_list->next_memory_threshold = MEMORY_DIFFERENCE * (alloc_list->total_memory_allocated / MEMORY_DIFFERENCE + 1); - (void) printf( "Memory allocated =%5.1f Megabytes\n", - (Real) alloc_list->total_memory_allocated / 1000000.0 ); + print( "Memory allocated =%5.1f Megabytes\n", + (Real) alloc_list->total_memory_allocated / 1000000.0 ); } } @@ -435,14 +427,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private void print_source_location( source_file, line_number, - time_of_alloc ) - char source_file[]; - int line_number; - Real time_of_alloc; +private void print_source_location( + char source_file[], + int line_number, + Real time_of_alloc ) { - (void) printf( "%s:%d\t%g seconds", source_file, line_number, - time_of_alloc ); + print( "%s:%d\t%g seconds", source_file, line_number, time_of_alloc ); } /* ----------------------------- MNI Header ----------------------------------- @@ -459,9 +449,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private void output_entry( file, entry ) - FILE *file; - skip_struct *entry; +private void output_entry( + FILE *file, + skip_struct *entry ) { (void) fprintf( file, "%s:%d\t%g seconds\n", entry->source_file, @@ -491,7 +481,7 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public int get_total_memory_alloced() +public int get_total_memory_alloced( void ) { return( alloc_list.total_memory_allocated ); } @@ -510,7 +500,7 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private Boolean alloc_checking_enabled() +private Boolean alloc_checking_enabled( void ) { #ifdef NO_DEBUG_ALLOC return( FALSE ); @@ -542,7 +532,7 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private Boolean size_display_enabled() +private Boolean size_display_enabled( void ) { #ifdef NO_DEBUG_ALLOC return( FALSE ); @@ -576,48 +566,47 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void record_ptr( ptr, n_bytes, source_file, line_number ) - void *ptr; - int n_bytes; - char source_file[]; - int line_number; +public void record_ptr( + void *ptr, + int n_bytes, + char source_file[], + int line_number ) { Real current_time; update_struct update_ptrs; - void check_initialized_alloc_list(); skip_struct *entry; if( alloc_checking_enabled() ) { - current_time = current_seconds(); + current_time = current_realtime_seconds(); check_initialized_alloc_list( &alloc_list ); if( n_bytes <= 0 ) { print_source_location( source_file, line_number, current_time ); - (void) printf( ": Alloc called with zero size.\n" ); + print( ": Alloc called with zero size.\n" ); abort_if_allowed(); } else if( ptr == (void *) 0 ) { print_source_location( source_file, line_number, current_time ); - (void) printf( ": Alloc returned a NIL pointer.\n" ); + print( ": Alloc returned a NIL pointer.\n" ); abort_if_allowed(); } else { (void) find_pointer_position( &alloc_list, ptr, &update_ptrs ); - if( check_overlap( &update_ptrs, ptr, n_bytes, &entry ) ) + if( check_overlap( &alloc_list, &update_ptrs, ptr, n_bytes, &entry)) { print_source_location( source_file, line_number, current_time ); - (void) printf( + print( ": Alloc returned a pointer overlapping an existing block:\n" ); print_source_location( entry->source_file, entry->line_number, entry->time_of_alloc ); - (void) printf( "\n" ); + print( "\n" ); abort_if_allowed(); } else @@ -647,12 +636,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void change_ptr( old_ptr, new_ptr, n_bytes, source_file, line_number ) - void *old_ptr; - void *new_ptr; - int n_bytes; - char source_file[]; - int line_number; +public void change_ptr( + void *old_ptr, + void *new_ptr, + int n_bytes, + char source_file[], + int line_number ) { char *orig_source; int orig_line; @@ -667,32 +656,32 @@ if( n_bytes <= 0 ) { print_source_location( source_file, line_number, - current_seconds() ); - (void) printf( ": Realloc called with zero size.\n" ); + current_realtime_seconds() ); + print( ": Realloc called with zero size.\n" ); abort_if_allowed(); } else if( !remove_ptr_from_alloc_list( &alloc_list, old_ptr, &orig_source, &orig_line, &time_of_alloc ) ) { print_source_location( source_file, line_number, - current_seconds() ); - (void) printf( - ": Tried to realloc a pointer not already alloced.\n"); + current_realtime_seconds() ); + print( ": Tried to realloc a pointer not already alloced.\n"); abort_if_allowed(); } else { (void) find_pointer_position( &alloc_list, new_ptr, &update_ptrs ); - if( check_overlap( &update_ptrs, new_ptr, n_bytes, &entry ) ) + if( check_overlap( &alloc_list, &update_ptrs, new_ptr, n_bytes, + &entry ) ) { print_source_location( source_file, line_number, - current_seconds()); - (void) printf( + current_realtime_seconds()); + print( ": Realloc returned a pointer overlapping an existing block:\n"); print_source_location( entry->source_file, entry->line_number, entry->time_of_alloc ); - (void) printf( "\n" ); + print( "\n" ); abort_if_allowed(); } else @@ -720,10 +709,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Boolean unrecord_ptr( ptr, source_file, line_number ) - void *ptr; - char source_file[]; - int line_number; +public Boolean unrecord_ptr( + void *ptr, + char source_file[], + int line_number ) { Boolean was_previously_alloced; char *orig_source; @@ -739,8 +728,8 @@ if( ptr == (void *) 0 ) { print_source_location( source_file, line_number, - current_seconds() ); - (void) printf( ": Tried to free a NIL pointer.\n" ); + current_realtime_seconds() ); + print( ": Tried to free a NIL pointer.\n" ); abort_if_allowed(); was_previously_alloced = FALSE; } @@ -748,8 +737,8 @@ &orig_line, &time_of_alloc ) ) { print_source_location( source_file, line_number, - current_seconds() ); - (void) printf( ": Tried to free a pointer not alloced.\n" ); + current_realtime_seconds() ); + print( ": Tried to free a pointer not alloced.\n" ); abort_if_allowed(); was_previously_alloced = FALSE; } @@ -773,11 +762,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void output_alloc_to_file( filename ) - char filename[]; +public void output_alloc_to_file( + char filename[] ) { FILE *file; - void output_alloc_list(); String date_str; if( alloc_checking_enabled() ) @@ -802,180 +790,3 @@ } } } - -#include <sys/time.h> -#include <def_string.h> - -/* ----------------------------- MNI Header ----------------------------------- -@NAME : get_date -@INPUT : -@OUTPUT : date_str -@RETURNS : -@DESCRIPTION: Fills in the date into the string. -@METHOD : -@GLOBALS : -@CALLS : -@CREATED : David MacDonald -@MODIFIED : ----------------------------------------------------------------------------- */ - -private void get_date( date_str ) - char date_str[]; -{ - time_t clock_time; - struct tm *time_tm; - char *str; -#ifndef sgi - time_t time(); -#endif - - (void) time( &clock_time ); - - time_tm = localtime( &clock_time ); - - str = asctime( time_tm ); - - (void) strcpy( date_str, str ); -} - -/* ----------------------------- MNI Header ----------------------------------- -@NAME : current_seconds -@INPUT : -@OUTPUT : -@RETURNS : Real -@DESCRIPTION: Returns the number of seconds since the first call to this. -@METHOD : -@GLOBALS : -@CALLS : -@CREATED : David MacDonald -@MODIFIED : ----------------------------------------------------------------------------- */ - -private Real current_seconds() -{ - static Boolean first_call = TRUE; - static struct timeval first; - struct timeval current; - Real secs; - - if( first_call ) - { - first_call = FALSE; - (void) gettimeofday( &first, (struct timezone *) 0 ); - secs = 0.0; - } - else - { - (void) gettimeofday( ¤t, (struct timezone *) 0 ); - secs = (double) current.tv_sec - (double) first.tv_sec + - 1.0e-6 * (double) (current.tv_usec - first.tv_usec); - } - - return( secs ); -} - -#include <def_math.h> - -#define MAX_RAND 2147483648.0 - -private Boolean initialized = FALSE; - -/* ----------------------------- MNI Header ----------------------------------- -@NAME : set_random_seed -@INPUT : seed -@OUTPUT : -@RETURNS : -@DESCRIPTION: Initializes the random number generation. -@METHOD : -@GLOBALS : -@CALLS : -@CREATED : David MacDonald -@MODIFIED : ----------------------------------------------------------------------------- */ - -private void set_random_seed( seed ) - int seed; -{ -#ifdef sgi - (void) srandom( (unsigned int) seed ); -#else - int srandom(); - (void) srandom( seed ); -#endif - - initialized = TRUE; -} - -/* ----------------------------- MNI Header ----------------------------------- -@NAME : check_initialized -@INPUT : -@OUTPUT : -@RETURNS : -@DESCRIPTION: Checks if the random number generator initialized. -@METHOD : -@GLOBALS : -@CALLS : -@CREATED : David MacDonald -@MODIFIED : ----------------------------------------------------------------------------- */ - -private void check_initialized() -{ - struct timeval t; - int seed; - - if( !initialized ) - { - (void) gettimeofday( &t, (struct timezone *) 0 ); - - seed = (int) t.tv_usec; - - set_random_seed( seed ); - } -} - -/* ----------------------------- MNI Header ----------------------------------- -@NAME : get_random -@INPUT : -@OUTPUT : -@RETURNS : int -@DESCRIPTION: Gets a random integer. -@METHOD : -@GLOBALS : -@CALLS : -@CREATED : David MacDonald -@MODIFIED : ----------------------------------------------------------------------------- */ - -private int get_random() -{ - check_initialized(); - -#ifdef sgi - return( random() ); -#else - { - long random(); - - return( (int) random() ); - } -#endif -} - -/* ----------------------------- MNI Header ----------------------------------- -@NAME : get_random_0_to_1 -@INPUT : -@OUTPUT : -@RETURNS : Real -@DESCRIPTION: Returns a random number between 0 and 1. -@METHOD : -@GLOBALS : -@CALLS : -@CREATED : David MacDonald -@MODIFIED : ----------------------------------------------------------------------------- */ - -private Real get_random_0_to_1() -{ - return( (Real) get_random() / MAX_RAND ); -}
--- a/volume_io/Prog_utils/files.c +++ b/volume_io/Prog_utils/files.c @@ -1,8 +1,12 @@ #include <def_mni.h> -#include <def_files.h> -#include <def_alloc.h> -#include <def_string.h> + +private Boolean has_no_extension( char [] ); + +public Boolean real_is_double() +{ + return( sizeof(Real) == 8 ); +} /* ----------------------------- MNI Header ----------------------------------- @NAME : file_exists @@ -17,8 +21,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Boolean file_exists( filename ) - char filename[]; +public Boolean file_exists( + char filename[] ) { Boolean exists; FILE *file; @@ -49,8 +53,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void remove_file( filename ) - char filename[]; +public void remove_file( + char filename[] ) { String command; @@ -74,11 +78,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status open_file( filename, io_type, file_format, file ) - char filename[]; - IO_types io_type; - File_formats file_format; - FILE **file; +public Status open_file( + char filename[], + IO_types io_type, + File_formats file_format, + FILE **file ) { Status status; String access_str; @@ -104,9 +108,7 @@ } else { - PRINT_ERROR( "Could not open file \"" ); - PRINT_ERROR( filename ); - PRINT_ERROR( "\".\n" ); + print( "Error: could not open file \"%s\".\n", filename ); *file = (FILE *) 0; status = ERROR; } @@ -133,13 +135,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status open_file_with_default_suffix( filename, default_suffix, - io_type, file_format, file ) - char filename[]; - char default_suffix[]; - IO_types io_type; - File_formats file_format; - FILE **file; +public Status open_file_with_default_suffix( + char filename[], + char default_suffix[], + IO_types io_type, + File_formats file_format, + FILE **file ) { Boolean suffix_added; String used_filename; @@ -179,8 +180,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -private Boolean has_no_extension( filename ) - char filename[]; +private Boolean has_no_extension( + char filename[] ) { char *str; @@ -206,9 +207,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status set_file_position( file, byte_position ) - FILE *file; - long byte_position; +public Status set_file_position( + FILE *file, + long byte_position ) { Status status; @@ -218,7 +219,7 @@ } else { - PRINT_ERROR( "Error setting the file position.\n" ); + print( "Error setting the file position.\n" ); status = ERROR; } @@ -238,8 +239,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status close_file( file ) - FILE *file; +public Status close_file( + FILE *file ) { (void) fclose( file ); @@ -260,9 +261,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void extract_directory( filename, directory ) - char filename[]; - char directory[]; +public void extract_directory( + char filename[], + char directory[] ) { int slash_index; @@ -299,10 +300,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void get_absolute_filename( filename, directory, abs_filename ) - char filename[]; - char directory[]; - char abs_filename[]; +public void get_absolute_filename( + char filename[], + char directory[], + char abs_filename[] ) { String save_filename; @@ -341,9 +342,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void strip_off_directories( filename, no_dirs ) - char filename[]; - char no_dirs[]; +public void strip_off_directories( + char filename[], + char no_dirs[] ) { int i; @@ -370,8 +371,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status flush_file( file ) - FILE *file; +public Status flush_file( + FILE *file ) { Status status; @@ -381,7 +382,7 @@ } else { - PRINT_ERROR( "Error flushing file.\n" ); + print( "Error flushing file.\n" ); status = ERROR; } @@ -401,9 +402,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_character( file, ch ) - FILE *file; - char *ch; +public Status input_character( + FILE *file, + char *ch ) { Status status; int c; @@ -436,9 +437,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status unget_character( file, ch ) - FILE *file; - char ch; +public Status unget_character( + FILE *file, + char ch ) { Status status; int c; @@ -466,9 +467,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_nonwhite_character( file, ch ) - FILE *file; - char *ch; +public Status input_nonwhite_character( + FILE *file, + char *ch ) { Status status; @@ -495,9 +496,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_character( file, ch ) - FILE *file; - char ch; +public Status output_character( + FILE *file, + char ch ) { Status status; @@ -528,9 +529,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status skip_input_until( file, search_char ) - FILE *file; - char search_char; +public Status skip_input_until( + FILE *file, + char search_char ) { Status status; char ch; @@ -560,9 +561,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_string( file, str ) - FILE *file; - char str[]; +public Status output_string( + FILE *file, + char str[] ) { Status status; @@ -570,7 +571,7 @@ status = OK; else { - PRINT_ERROR( "Error outputting string.\n" ); + print( "Error outputting string.\n" ); status = ERROR; } @@ -594,11 +595,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_string( file, str, string_length, termination_char ) - FILE *file; - char str[]; - int string_length; - char termination_char; +public Status input_string( + FILE *file, + char str[], + int string_length, + char termination_char ) { int i; char ch; @@ -615,7 +616,7 @@ if( i >= string_length - 1 ) { - PRINT_ERROR( "Input string too long.\n" ); + print( "Input string too long.\n" ); status = ERROR; } else @@ -649,16 +650,14 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_quoted_string( file, str, str_length ) - FILE *file; - char str[]; - int str_length; +public Status input_quoted_string( + FILE *file, + char str[], + int str_length ) { int i; char ch; Status status; - Status input_nonwhite_character(); - Status input_character(); status = input_nonwhite_character( file, &ch ); @@ -699,9 +698,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_quoted_string( file, str ) - FILE *file; - char str[]; +public Status output_quoted_string( + FILE *file, + char str[] ) { Status status; @@ -728,11 +727,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_binary_data( file, data, element_size, n ) - FILE *file; - VOID *data; - size_t element_size; - int n; +public Status input_binary_data( + FILE *file, + void *data, + size_t element_size, + int n ) { Status status; int n_done; @@ -743,9 +742,9 @@ if( n_done != n ) { #ifdef ERROR_MESSAGES - PRINT_ERROR( "Error inputting binary data.\n" ); - PRINT( " (%d out of %d items of size %d).\n", n_done, n, - (int) element_size ); + print( "Error inputting binary data.\n" ); + print( " (%d out of %d items of size %d).\n", n_done, n, + (int) element_size ); #endif status = ERROR; } @@ -769,11 +768,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_binary_data( file, data, element_size, n ) - FILE *file; - VOID *data; - size_t element_size; - int n; +public Status output_binary_data( + FILE *file, + void *data, + size_t element_size, + int n ) { Status status; int n_done; @@ -783,9 +782,9 @@ n_done = fwrite( data, element_size, n, file ); if( n_done != n ) { - PRINT_ERROR( "Error outputting binary data.\n" ); - PRINT( " (%d out of %d items of size %d).\n", n_done, n, - (int) element_size ); + print( "Error outputting binary data.\n" ); + print( " (%d out of %d items of size %d).\n", n_done, n, + (int) element_size ); status = ERROR; } @@ -805,17 +804,16 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_newline( file ) - FILE *file; +public Status input_newline( + FILE *file ) { Status status; - Status skip_input_until(); status = skip_input_until( file, '\n' ); - if( status == END_OF_FILE ) + if( status != OK ) { - PRINT_ERROR( "Error inputting newline.\n" ); + print( "Error inputting newline.\n" ); status = ERROR; } @@ -835,8 +833,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_newline( file ) - FILE *file; +public Status output_newline( + FILE *file ) { Status status; @@ -844,7 +842,7 @@ status = OK; else { - PRINT_ERROR( "Error outputting newline.\n" ); + print( "Error outputting newline.\n" ); status = ERROR; } @@ -865,10 +863,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_line( file, line, str_length ) - FILE *file; - char line[]; - int str_length; +public Status input_line( + FILE *file, + char line[], + int str_length ) { Status status; int i; @@ -904,13 +902,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_boolean( file, b ) - FILE *file; - Boolean *b; +public Status input_boolean( + FILE *file, + Boolean *b ) { Status status; char ch; - Status input_nonwhite_character(); status = input_nonwhite_character( file, &ch ); @@ -941,9 +938,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_boolean( file, b ) - FILE *file; - Boolean b; +public Status output_boolean( + FILE *file, + Boolean b ) { Status status; char *str; @@ -957,7 +954,7 @@ if( fprintf( file, " %s", str ) > 0 ) { - PRINT_ERROR( "Error outputting Boolean.\n" ); + print( "Error outputting Boolean.\n" ); status = ERROR; } @@ -977,9 +974,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_short( file, s ) - FILE *file; - short *s; +public Status input_short( + FILE *file, + short *s ) { Status status; @@ -1005,9 +1002,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_short( file, s ) - FILE *file; - short s; +public Status output_short( + FILE *file, + short s ) { Status status; @@ -1015,7 +1012,7 @@ status = OK; else { - PRINT_ERROR( "Error outputting short.\n" ); + print( "Error outputting short.\n" ); status = ERROR; } @@ -1035,9 +1032,7 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_int( file, i ) - FILE *file; - int *i; +public Status input_int( FILE * file, int * i ) { Status status; @@ -1063,9 +1058,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_int( file, i ) - FILE *file; - int i; +public Status output_int( + FILE *file, + int i ) { Status status; @@ -1073,7 +1068,7 @@ status = OK; else { - PRINT_ERROR( "Error outputting int.\n" ); + print( "Error outputting int.\n" ); status = ERROR; } @@ -1093,20 +1088,19 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_real( file, r ) - FILE *file; - Real *r; +public Status input_real( + FILE *file, + Real *r ) { Status status; - if( fscanf( file, "%f", r ) == 1 ) - status = OK; + if( real_is_double() ) + { + status = input_double( file, (double *) r ); + } else { -#ifdef ERROR_MESSAGES - PRINT_ERROR( "Error inputting float.\n" ); -#endif - status = ERROR; + status = input_float( file, (float *) r ); } return( status ); @@ -1126,17 +1120,81 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_real( file, r ) - FILE *file; - Real r; +public Status output_real( + FILE *file, + Real r ) +{ + Status status; + + if( real_is_double() ) + { + status = output_double( file, (double) r ); + } + else + { + status = output_float( file, (float) r ); + } + + return( status ); +} + +/* ----------------------------- MNI Header ----------------------------------- +@NAME : input_float +@INPUT : file +@OUTPUT : f +@RETURNS : Status +@DESCRIPTION: Inputs an ascii float. +@METHOD : +@GLOBALS : +@CALLS : +@CREATED : David MacDonald +@MODIFIED : +---------------------------------------------------------------------------- */ + +public Status input_float( + FILE *file, + float *f ) { Status status; - if( fprintf( file, " %g", r ) > 0 ) + if( fscanf( file, "%f", f ) == 1 ) status = OK; else { - PRINT_ERROR( "Error outputting float.\n" ); +#ifdef ERROR_MESSAGES + print( "Error inputting float.\n" ); +#endif + status = ERROR; + } + + return( status ); +} + +/* ----------------------------- MNI Header ----------------------------------- +@NAME : output_float +@INPUT : file + : f +@OUTPUT : +@RETURNS : Status +@DESCRIPTION: Outputs an ascii float value. +@METHOD : +@GLOBALS : +@CALLS : +@CREATED : David MacDonald +@MODIFIED : +---------------------------------------------------------------------------- */ + +public Status output_float( + FILE *file, + float f ) +{ + Status status; + + if( fprintf( file, " %g", f ) > 0 ) + status = OK; + else + { + print( "Error outputting float.\n" ); status = ERROR; } @@ -1156,9 +1214,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status input_double( file, d ) - FILE *file; - double *d; +public Status input_double( + FILE *file, + double *d ) { Status status; @@ -1167,7 +1225,7 @@ else { #ifdef ERROR_MESSAGES - PRINT_ERROR( "Error inputting double.\n" ); + print( "Error inputting double.\n" ); #endif status = ERROR; } @@ -1189,9 +1247,9 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status output_double( file, d ) - FILE *file; - double d; +public Status output_double( + FILE *file, + double d ) { Status status; @@ -1199,7 +1257,7 @@ status = OK; else { - PRINT_ERROR( "Error outputting double.\n" ); + print( "Error outputting double.\n" ); status = ERROR; } @@ -1223,12 +1281,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_binary_data( file, io_flag, data, element_size, n ) - FILE *file; - IO_types io_flag; - VOID *data; - size_t element_size; - int n; +public Status io_binary_data( + FILE *file, + IO_types io_flag, + void *data, + size_t element_size, + int n ) { Status status; @@ -1255,10 +1313,10 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_newline( file, io_flag, format ) - FILE *file; - IO_types io_flag; - File_formats format; +public Status io_newline( + FILE *file, + IO_types io_flag, + File_formats format ) { Status status; @@ -1292,17 +1350,15 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_quoted_string( file, io_flag, format, str, str_length ) - FILE *file; - IO_types io_flag; - File_formats format; - char str[]; - int str_length; +public Status io_quoted_string( + FILE *file, + IO_types io_flag, + File_formats format, + char str[], + int str_length ) { int length; Status status; - Status io_int(); - Status input_character(); status = OK; @@ -1322,13 +1378,13 @@ if( io_flag == READ_FILE && length >= str_length ) { - PRINT( "String too large: " ); + print( "String too large: " ); status = ERROR; } if( status == OK ) { - status = io_binary_data( file, io_flag, (VOID *) str, + status = io_binary_data( file, io_flag, (void *) str, sizeof(str[0]), length ); } @@ -1337,7 +1393,7 @@ if( status != OK ) { - PRINT_ERROR( "Error in quoted string in file.\n" ); + print( "Error in quoted string in file.\n" ); } return( status ); @@ -1359,11 +1415,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_boolean( file, io_flag, format, b ) - FILE *file; - IO_types io_flag; - File_formats format; - Boolean *b; +public Status io_boolean( + FILE *file, + IO_types io_flag, + File_formats format, + Boolean *b ) { Status status; @@ -1377,7 +1433,7 @@ status = output_boolean( file, *b ); } else - status = io_binary_data( file, io_flag, (VOID *) b, sizeof(*b), 1 ); + status = io_binary_data( file, io_flag, (void *) b, sizeof(*b), 1 ); return( status ); } @@ -1398,11 +1454,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_short( file, io_flag, format, short_int ) - FILE *file; - IO_types io_flag; - File_formats format; - short *short_int; +public Status io_short( + FILE *file, + IO_types io_flag, + File_formats format, + short *short_int ) { Status status; @@ -1416,7 +1472,7 @@ status = output_short( file, *short_int ); } else - status = io_binary_data( file, io_flag, (VOID *) short_int, + status = io_binary_data( file, io_flag, (void *) short_int, sizeof(*short_int), 1 ); return( status ); @@ -1438,11 +1494,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_unsigned_char( file, io_flag, format, c ) - FILE *file; - IO_types io_flag; - File_formats format; - unsigned char *c; +public Status io_unsigned_char( + FILE *file, + IO_types io_flag, + File_formats format, + unsigned char *c ) { int i; Status status; @@ -1457,7 +1513,7 @@ *c = i; else { - PRINT_ERROR( "Error inputting unsigned char.\n" ); + print( "Error inputting unsigned char.\n" ); status = ERROR; } } @@ -1465,13 +1521,13 @@ { if( fprintf( file, "%d", (int) *c ) != 1 ) { - PRINT_ERROR( "Error outputting unsigned char.\n" ); + print( "Error outputting unsigned char.\n" ); status = ERROR; } } } else - status = io_binary_data( file, io_flag, (VOID *) c, sizeof(*c), 1 ); + status = io_binary_data( file, io_flag, (void *) c, sizeof(*c), 1 ); return( status ); } @@ -1492,11 +1548,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_int( file, io_flag, format, i ) - FILE *file; - IO_types io_flag; - File_formats format; - int *i; +public Status io_int( + FILE *file, + IO_types io_flag, + File_formats format, + int *i ) { Status status; @@ -1510,7 +1566,7 @@ status = output_int( file, *i ); } else - status = io_binary_data( file, io_flag, (VOID *) i, sizeof(*i), 1 ); + status = io_binary_data( file, io_flag, (void *) i, sizeof(*i), 1 ); return( status ); } @@ -1531,11 +1587,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_real( file, io_flag, format, r ) - FILE *file; - IO_types io_flag; - File_formats format; - Real *r; +public Status io_real( + FILE *file, + IO_types io_flag, + File_formats format, + Real *r ) { Status status; @@ -1549,7 +1605,7 @@ status = output_real( file, *r ); } else - status = io_binary_data( file, io_flag, (VOID *) r, sizeof(*r), 1 ); + status = io_binary_data( file, io_flag, (void *) r, sizeof(*r), 1 ); return( status ); } @@ -1570,11 +1626,11 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_double( file, io_flag, format, d ) - FILE *file; - IO_types io_flag; - File_formats format; - double *d; +public Status io_double( + FILE *file, + IO_types io_flag, + File_formats format, + double *d ) { Status status; @@ -1588,7 +1644,7 @@ status = output_double( file, *d ); } else - status = io_binary_data( file, io_flag, (VOID *) d, sizeof(*d), 1 ); + status = io_binary_data( file, io_flag, (void *) d, sizeof(*d), 1 ); return( status ); } @@ -1610,12 +1666,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_ints( file, io_flag, format, n, ints ) - FILE *file; - IO_types io_flag; - File_formats format; - int n; - int *ints[]; +public Status io_ints( + FILE *file, + IO_types io_flag, + File_formats format, + int n, + int *ints[] ) { Status status; int i; @@ -1652,7 +1708,7 @@ } else { - status = io_binary_data( file, io_flag, (VOID *) *ints, + status = io_binary_data( file, io_flag, (void *) *ints, sizeof((*ints)[0]), n ); } } @@ -1677,12 +1733,12 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Status io_unsigned_chars( file, io_flag, format, n, unsigned_chars ) - FILE *file; - IO_types io_flag; - File_formats format; - int n; - unsigned char *unsigned_chars[]; +public Status io_unsigned_chars( + FILE *file, + IO_types io_flag, + File_formats format, + int n, + unsigned char *unsigned_chars[] ) { Status status; int i; @@ -1713,7 +1769,7 @@ } else { - status = io_binary_data( file, io_flag, (VOID *) (*unsigned_chars), + status = io_binary_data( file, io_flag, (void *) (*unsigned_chars), sizeof((*unsigned_chars)[0]), n ); } }
--- a/volume_io/Prog_utils/time.c +++ b/volume_io/Prog_utils/time.c @@ -4,7 +4,6 @@ #include <sys/param.h> #include <limits.h> #include <def_mni.h> -#include <def_string.h> /* ----------------------------- MNI Header ----------------------------------- @NAME : current_cpu_seconds @@ -19,7 +18,7 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Real current_cpu_seconds() +public Real current_cpu_seconds( void ) { struct tms buffer; Real cpu_time; @@ -45,7 +44,7 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public Real current_realtime_seconds() +public Real current_realtime_seconds( void ) { static Boolean first_call = TRUE; static struct timeval first; @@ -83,16 +82,16 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void format_time( str, format, seconds ) - char str[]; - char format[]; - Real seconds; +public void format_time( + char str[], + char format[], + Real seconds ) { int i; static char *units[] = { "us", "ms", "sec", "min", "hrs", "days", "years" }; - static Real scale[] = { 1000.0, 1000.0, 60.0, 60.0, 24.0, 365.0 }; + static Real scales[] = { 1000.0, 1000.0, 60.0, 60.0, 24.0, 365.0 }; Boolean negative; negative = seconds < 0.0; @@ -102,9 +101,9 @@ for_less( i, 0, SIZEOF_STATIC_ARRAY(units)-1 ) { - if( seconds > 2.0 * scale[i] ) + if( seconds > 2.0 * scales[i] ) { - seconds /= scale[i]; + seconds /= scales[i]; } else { @@ -112,7 +111,7 @@ } } - seconds = (int) (10.0 * seconds + 0.5) / 10.0; + seconds = ROUND( 10.0 * seconds ) / 10.0; if( negative ) seconds = -seconds; @@ -133,15 +132,15 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void print_time( format, seconds ) - char format[]; - Real seconds; +public void print_time( + char format[], + Real seconds ) { String str; format_time( str, format, seconds ); - (void) printf( "%s", str ); + print( "%s", str ); } /* ----------------------------- MNI Header ----------------------------------- @@ -157,8 +156,8 @@ @MODIFIED : ---------------------------------------------------------------------------- */ -public void get_clock_time( time_str ) - char time_str[]; +public void get_clock_time( + char time_str[] ) { time_t clock_time; struct tm *time_tm; @@ -176,8 +175,7 @@ (void) strcpy( time_str, str ); } -public void sleep_program( seconds ) - Real seconds; +public void sleep_program( Real seconds ) { #ifdef sgi long ticks; @@ -186,3 +184,35 @@ sginap( ticks ); #endif } + +/* ----------------------------- MNI Header ----------------------------------- +@NAME : get_date +@INPUT : +@OUTPUT : date_str +@RETURNS : +@DESCRIPTION: Fills in the date into the string. +@METHOD : +@GLOBALS : +@CALLS : +@CREATED : David MacDonald +@MODIFIED : +---------------------------------------------------------------------------- */ + +public void get_date( + char date_str[] ) +{ + time_t clock_time; + struct tm *time_tm; + char *str; +#ifndef sgi + time_t time(); +#endif + + (void) time( &clock_time ); + + time_tm = localtime( &clock_time ); + + str = asctime( time_tm ); + + (void) strcpy( date_str, str ); +}
--- a/volume_io/Volumes/input_volume.c +++ b/volume_io/Volumes/input_volume.c @@ -3,17 +3,28 @@ #define N_VALUES 256 +private void create_world_transform( + Point *origin, + Vector axes[N_DIMENSIONS], + Real thickness[N_DIMENSIONS], + Transform *transform ); + public Status input_volume( char filename[], volume_struct *volume ) { Status status; char name[MAX_NC_NAME]; - int x, y, z, volume_axis; + int axis_index[N_DIMENSIONS]; double slice_separation[N_DIMENSIONS]; double start_position[N_DIMENSIONS]; double direction_cosines[N_DIMENSIONS][N_DIMENSIONS]; + Point origin; + Vector axes[N_DIMENSIONS]; + Vector x_offset, y_offset, z_offset, start_offset; Volume_type *image; + int indices[N_DIMENSIONS], sizes[N_DIMENSIONS]; + int index0, index1, index2; int axis; long length; int icv, cdfid, img, dimvar; @@ -43,63 +54,113 @@ return( status ); } + axis_index[X] = -1; + axis_index[Y] = -1; + axis_index[Z] = -1; + for_less( axis, 0, ndims ) { - volume_axis = 2 - axis; + (void) ncdiminq( cdfid, dim[axis], name, &length ); + sizes[axis] = length; - (void) ncdiminq( cdfid, dim[axis], name, &length ); - volume->sizes[volume_axis] = length; + if( EQUAL_STRINGS( name, MIxspace ) ) + axis_index[axis] = X; + else if( EQUAL_STRINGS( name, MIyspace ) ) + axis_index[axis] = Y; + else if( EQUAL_STRINGS( name, MIzspace ) ) + axis_index[axis] = Z; + else + { + print("Error: cannot handle dimensions other than x, y, and z.\n"); + print(" offending dimension: %s\n", name ); + status = ERROR; + return( status ); + } + + slice_separation[axis] = 1.0; + start_position[axis] = 0.0; + direction_cosines[axis][0] = 0.0; + direction_cosines[axis][1] = 0.0; + direction_cosines[axis][2] = 0.0; + direction_cosines[axis][axis_index[axis]] = 1.0; ncopts = 0; dimvar = ncvarid( cdfid, name ); if( dimvar != MI_ERROR ) { - if( miattget1( cdfid, dimvar, MIstep, NC_DOUBLE, - (void *) &slice_separation[volume_axis] ) == MI_ERROR ) - { - slice_separation[volume_axis] = 1.0; - } + (void) miattget1( cdfid, dimvar, MIstep, NC_DOUBLE, + (void *) &slice_separation[axis] ); - if( miattget1( cdfid, dimvar, MIstart, NC_DOUBLE, - (void *) &start_position[volume_axis] ) == MI_ERROR ) - { - start_position[volume_axis] = 0.0; - } + (void) miattget1( cdfid, dimvar, MIstart, NC_DOUBLE, + (void *) &start_position[axis] ); - if( miattget( cdfid, dimvar, MIstart, NC_DOUBLE, N_DIMENSIONS, - (void *) direction_cosines[volume_axis], (int *) 0 ) - == MI_ERROR ) - { - direction_cosines[volume_axis][0] = 0.0; - direction_cosines[volume_axis][1] = 0.0; - direction_cosines[volume_axis][2] = 0.0; - direction_cosines[volume_axis][volume_axis] = 1.0; - } + (void) miattget( cdfid, dimvar, MIdirection_cosines, NC_DOUBLE, + N_DIMENSIONS, (void *) direction_cosines[axis], + (int *) 0 ); } ncopts = NC_VERBOSE | NC_FATAL; } + if( axis_index[X] == -1 || axis_index[Y] == -1 || axis_index[Z] == -1 ) + { + print( "Error: missing some of the 3 dimensions.\n" ); + status = ERROR; + return( status ); + } + + for_less( axis, 0, N_DIMENSIONS ) + { + volume->thickness[axis_index[axis]] = (Real) slice_separation[axis]; + volume->sizes[axis_index[axis]] = sizes[axis]; + fill_Vector( axes[axis_index[axis]], + direction_cosines[axis][0], + direction_cosines[axis][1], + direction_cosines[axis][2] ); + NORMALIZE_VECTOR( axes[axis_index[axis]], axes[axis_index[axis]] ); + if( null_Vector( &axes[axis_index[axis]] ) ) + { + fill_Vector( axes[axis_index[axis]], + 0.0, 0.0, 0.0 ); + Vector_coord(axes[axis_index[axis]],axis_index[axis]) = 1.0; + } + } + + SCALE_VECTOR( x_offset, axes[X], start_position[axis_index[X]] ); + SCALE_VECTOR( y_offset, axes[Y], start_position[axis_index[Y]] ); + SCALE_VECTOR( z_offset, axes[Z], start_position[axis_index[Z]] ); + ADD_VECTORS( start_offset, x_offset, y_offset ); + ADD_VECTORS( start_offset, start_offset, z_offset ); + + CONVERT_VECTOR_TO_POINT( origin, start_offset ); + + create_world_transform( &origin, axes, volume->thickness, + &volume->world_transform ); + ALLOC3D( status, volume->data, volume->sizes[X], volume->sizes[Y], volume->sizes[Z] ); - ALLOC( status, image, volume->sizes[X] * volume->sizes[Y] ); + ALLOC( status, image, sizes[1] * sizes[2] ); - for_less( z, 0, volume->sizes[Z] ) + for_less( index0, 0, sizes[0] ) { - start[0] = z; + indices[axis_index[0]] = index0; + start[0] = index0; start[1] = 0; start[2] = 0; count[0] = 1; - count[1] = volume->sizes[Y]; - count[2] = volume->sizes[X]; + count[1] = sizes[1]; + count[2] = sizes[2]; (void) miicv_get( icv, start, count, (void *) image ); - for_less( y, 0, volume->sizes[Y] ) + for_less( index1, 0, sizes[1] ) { - for_less( x, 0, volume->sizes[X] ) + indices[axis_index[1]] = index1; + for_less( index2, 0, sizes[2] ) { - volume->data[x][y][z] = image[IJ(y,x,volume->sizes[X])]; + indices[axis_index[2]] = index2; + volume->data[indices[X]][indices[Y]][indices[Z]] = + image[IJ(index1,index2,sizes[2])]; } } } @@ -109,15 +170,50 @@ (void) ncclose( cdfid ); (void) miicv_free( icv ); - volume->thickness[X] = (Real) slice_separation[X]; - volume->thickness[Y] = (Real) slice_separation[Y]; - volume->thickness[Z] = (Real) slice_separation[Z]; volume->value_scale = 1.0; volume->value_translation = 0.0; return( status ); } +private void create_world_transform( + Point *origin, + Vector axes[N_DIMENSIONS], + Real thickness[N_DIMENSIONS], + Transform *transform ) +{ + Vector x_axis, y_axis, z_axis; + + x_axis = axes[X]; + y_axis = axes[Y]; + z_axis = axes[Z]; + +#ifdef FORCE_ORTHONORMAL + CROSS_VECTORS( z_axis, x_axis, y_axis ); + + if( DOT_VECTORS(z_axis,axes[Z]) < 0.0 ) + { + SCALE_VECTOR( z_axis, z_axis, -1.0 ); + CROSS_VECTORS( y_axis, x_axis, z_axis ); + } + else + { + CROSS_VECTORS( y_axis, z_axis, x_axis ); + } + + NORMALIZE_VECTOR( x_axis, x_axis ); + NORMALIZE_VECTOR( y_axis, y_axis ); + NORMALIZE_VECTOR( z_axis, z_axis ); +#endif + + SCALE_VECTOR( x_axis, x_axis, thickness[X] ); + SCALE_VECTOR( y_axis, y_axis, thickness[Y] ); + SCALE_VECTOR( z_axis, z_axis, thickness[Z] ); + + make_change_to_bases_transform( origin, &x_axis, &y_axis, &z_axis, + transform ); +} + public Status input_fake_volume( char filename[], volume_struct *volume ) /* ARGSUSED */