# HG changeset patch # User bert # Date 1108497594 0 # Node ID f1a50ec0e51c51e0420f3e0bab14f0b7683af3c1 # Parent 7cae39d8a3702a96f3208e59e2595e0dbb5c0810 Initial checkin on 1.X branch diff --git a/conversion/ecattominc/dump_ecat_header.c b/conversion/ecattominc/dump_ecat_header.c --- a/conversion/ecattominc/dump_ecat_header.c +++ b/conversion/ecattominc/dump_ecat_header.c @@ -10,7 +10,13 @@ @CREATED : January 10, 1996 (Peter Neelin) @MODIFIED : * $Log: dump_ecat_header.c,v $ - * Revision 6.1 1999-10-29 17:52:00 neelin + * Revision 6.2.2.1 2005-02-15 19:59:54 bert + * Initial checkin on 1.X branch + * + * Revision 6.2 2005/01/19 19:46:00 bert + * Changes from Anthonin Reilhac + * + * Revision 6.1 1999/10/29 17:52:00 neelin * Fixed Log keyword * * Revision 6.0 1997/09/12 13:24:22 neelin @@ -38,14 +44,14 @@ ---------------------------------------------------------------------------- */ #ifndef lint -static char rcsid[]="$Header: /private-cvsroot/minc/conversion/ecattominc/dump_ecat_header.c,v 6.1 1999-10-29 17:52:00 neelin Exp $"; +static char rcsid[]="$Header: /private-cvsroot/minc/conversion/ecattominc/dump_ecat_header.c,v 6.2.2.1 2005-02-15 19:59:54 bert Exp $"; #endif #include #include #include #include -#include +#include "ecat_file.h" /* Main program */ diff --git a/conversion/ecattominc/ecat_file.c b/conversion/ecattominc/ecat_file.c --- a/conversion/ecattominc/ecat_file.c +++ b/conversion/ecattominc/ecat_file.c @@ -5,7 +5,13 @@ @CREATED : January 4, 1996 (Peter Neelin) @MODIFIED : * $Log: ecat_file.c,v $ - * Revision 6.1 1999-10-29 17:52:01 neelin + * Revision 6.2.2.1 2005-02-15 19:59:54 bert + * Initial checkin on 1.X branch + * + * Revision 6.2 2005/01/19 19:46:00 bert + * Changes from Anthonin Reilhac + * + * Revision 6.1 1999/10/29 17:52:01 neelin * Fixed Log keyword * * Revision 6.0 1997/09/12 13:24:22 neelin @@ -33,15 +39,17 @@ ---------------------------------------------------------------------------- */ #ifndef lint -static char rcsid[]="$Header: /private-cvsroot/minc/conversion/ecattominc/ecat_file.c,v 6.1 1999-10-29 17:52:01 neelin Exp $"; +static char rcsid[]="$Header: /private-cvsroot/minc/conversion/ecattominc/ecat_file.c,v 6.2.2.1 2005-02-15 19:59:54 bert Exp $"; #endif #include #include #include #include -#include -#include +#include "ecat_file.h" +#include "machine_indep.h" + +/*#include */ /* Set some standard macros */ #ifndef SEEK_SET @@ -51,10 +59,6 @@ # define TRUE 1 # define FALSE 0 #endif -#define MALLOC(size) ((void *) malloc_check(size)) -#define FREE(ptr) free(ptr) -#define REALLOC(ptr, size) ((void *) realloc_check(ptr, size)) -#define CALLOC(nelem, elsize) ((void *) calloc(nelem, elsize)) /* Constants */ #define BLOCK_SIZE 512 @@ -99,19 +103,19 @@ /* ECAT file Type */ struct Ecat_file { - FILE *file_pointer; - Ecat_header_description_type *header_description; - int vax_byte_order; - int num_planes; - int num_frames; - int num_bed_positions; - int num_gates; - int num_volumes; - unsigned char *main_header; - long cur_subhdr_offset; - unsigned char *subheader; - int num_subhdrs; - long *subhdr_offsets; + FILE *file_pointer; + Ecat_header_description_type *header_description; + int vax_byte_order; + int num_planes; + int num_frames; + int num_bed_positions; + int num_gates; + int num_volumes; + unsigned char *main_header; + long cur_subhdr_offset; + unsigned char *subheader; + int num_subhdrs; + long *subhdr_offsets; }; typedef enum { @@ -146,8 +150,7 @@ private long get_dirblock(Ecat_file *file, long *dirblock, int offset); private int ecat_get_subhdr_offset(Ecat_file *file, int volume, int slice, long *offset); -private void *malloc_check(size_t size); -private void *realloc_check(void *ptr, size_t size); + /* ----------------------------- MNI Header ----------------------------------- @@ -169,6 +172,8 @@ /* Allocate space for an ecat file structure */ file = (void *) MALLOC(sizeof(*file)); + + file->main_header = (void *) MALLOC(MAIN_HEADER_SIZE); file->subheader = (void *) MALLOC(SUBHEADER_SIZE); file->cur_subhdr_offset = -1; @@ -216,13 +221,14 @@ if (file->num_volumes < file->num_gates) file->num_volumes = file->num_gates; + /* Read the directory structure */ if (ecat_read_directory(file)) { ecat_close(file); return NULL; } + /* Return the file pointer */ - /* Return the file pointer */ return file; } @@ -571,6 +577,7 @@ Ecat_field_name field, int index, int *ivalue, double *fvalue, char *svalue) { + return ecat_get_value(file, ECAT_MAIN_HEADER, 0, 0, field, index, ivalue, fvalue, svalue); } @@ -674,29 +681,29 @@ /* Get the value and convert it */ switch (type) { case ecat_byte: - byte_value = header[offset]; - if (ivalue != NULL) *ivalue = byte_value; - if (fvalue != NULL) *fvalue = byte_value; - if (svalue != NULL) (void) sprintf(svalue, "%d", (int) byte_value); - break; + byte_value = header[offset]; + if (ivalue != NULL) *ivalue = byte_value; + if (fvalue != NULL) *fvalue = byte_value; + if (svalue != NULL) (void) sprintf(svalue, "%d", (int) byte_value); + break; case ecat_short: - if (file->vax_byte_order) { - get_vax_short(1, &header[offset], &short_value); - } - else { - (void) memcpy(&short_value, &header[offset], sizeof(short)); - } - if (ivalue != NULL) *ivalue = short_value; - if (fvalue != NULL) *fvalue = short_value; - if (svalue != NULL) (void) sprintf(svalue, "%d", (int) short_value); - break; + if (file->vax_byte_order) { + get_vax_short(1, &header[offset], &short_value); + } + else { + get_short_value(& header[offset], &short_value); + } + if (ivalue != NULL) *ivalue = short_value; + if (fvalue != NULL) *fvalue = short_value; + if (svalue != NULL) (void) sprintf(svalue, "%d", (int) short_value); + break; case ecat_long: - if (file->vax_byte_order) { - get_vax_long(1, &header[offset], &long_value); - } - else { - (void) memcpy(&long_value, &header[offset], sizeof(long)); - } + if (file->vax_byte_order) { + get_vax_long(1, &header[offset], &long_value); + } + else { + get_long_value(& header[offset], &long_value); + } if (ivalue != NULL) *ivalue = long_value; if (fvalue != NULL) *fvalue = long_value; if (svalue != NULL) (void) sprintf(svalue, "%d", (int) long_value); @@ -704,10 +711,10 @@ case ecat_float: offset += index * sizeof(float); if (file->vax_byte_order) { - get_vax_float(1, &header[offset], &float_value); + get_vax_float(1, &header[offset], &float_value); } else { - (void) memcpy(&float_value, &header[offset], sizeof(float)); + get_long_value(& header[offset], &float_value); } if (ivalue != NULL) *ivalue = float_value; if (fvalue != NULL) *fvalue = float_value; @@ -942,6 +949,8 @@ file->subhdr_offsets = MALLOC(num_alloc * sizeof(file->subhdr_offsets[0])); + + /* Reading directory blocks until done */ nextblock = FIRST_DIRBLOCK; do { @@ -953,6 +962,7 @@ return TRUE; } + /* Get a pointer to the next block and the number of entries used */ nextblock = get_dirblock(file, dirblock, DRBLK_NEXT); num_used = get_dirblock(file, dirblock, DRBLK_NUMUSED); @@ -997,10 +1007,11 @@ long value; if (file->header_description == ECAT_VER_PRE7) { - get_vax_long(1, &dirblock[offset], &value); + /*get_vax_long(1, &dirblock[offset], &value);*/ } else if (file->header_description == ECAT_VER_7) { - value = dirblock[offset]; + /* value = dirblock[offset];*/ + get_long_value(&dirblock[offset], &value); } else { return 0; @@ -1096,7 +1107,13 @@ break; case 2: if (file->header_description == ECAT_VER_PRE7) { - get_vax_short(image_npix, image, image); + /*get_vax_short(image_npix, image, image);*/ + } + else { + for (ipix=0; ipix @@ -67,8 +85,10 @@ #include #include #include -#include -#include +/*#include modif anthonin */ +#include "ecat_file.h" + + /* Type declarations */ typedef struct { @@ -186,6 +206,14 @@ #define MINIMUM_HALFLIFE 0.1 #define FWHM_SCALE_FOR_HANN 1.082 + +/* we don't need mni_def anymore*/ + +/*#define MALLOC(size) ((void *) malloc(size)) +#define FREE(ptr) free( (void *) ptr) +#define REALLOC(ptr, size) ((void *) realloc(ptr, size))*/ + + /* Main program */ int main(int argc, char *argv[]) @@ -235,9 +263,9 @@ }; /* Other variables */ - char *pname; - char *mincfile; - char *ecat_filename; + char *pname; /*name of the present command ->argv[0]*/ + char *mincfile; /*name of the minc file = output*/ + char *ecat_filename; /*name of the ecat7 file = input*/ int num_frames; int num_bed_positions; int sort_over_time; @@ -253,7 +281,7 @@ short *image; Ecat_file *ecat_fp; int status; - char *tm_stamp; + char *tm_stamp; /******** pk for minchistory*/ double first_z, last_z, zstep; /* Get time stamp */ @@ -306,6 +334,8 @@ exit(EXIT_FAILURE); } + + /* Get number of frames and bed positions to see if we are varying over time or interleaving slices */ num_frames = ecat_get_num_frames(ecat_fp); @@ -1435,7 +1465,7 @@ general_info_type *general_info) /* ARGSUSED */ { - long npix, ix, iy, y_offset, off1, off2; + long npix, in, off; int pmax; int lvalue; short temp; @@ -1443,20 +1473,16 @@ /* Get the image from the file */ if (ecat_get_image(ecat_fp, frame_num, slice_num, image)) return TRUE; - + /* Flip the image to give positive x & y axes */ npix = frame_info->image_xsize * frame_info->image_ysize; - for (iy=0; iyimage_ysize/2; iy++) { - y_offset = iy * frame_info->image_xsize; - for (ix=0; iximage_xsize; ix++) { - off1 = y_offset + ix; - off2 = npix - off1 - 1; - temp = image[off1]; - image[off1] = image[off2]; - image[off2] = temp; - } + + for(in = 0; in < npix/2; in++) { + off = npix - in - 1; + temp = image[off]; + image[off] = image[in]; + image[in] = temp; } - /* Get image and pixel max */ if (ecat_get_subhdr_value(ecat_fp, frame_num, slice_num, ECAT_Image_Max, 0, &pmax, NULL, NULL) || @@ -1483,7 +1509,6 @@ return FALSE; } - /* ----------------------------- MNI Header ----------------------------------- @NAME : write_minc_slice @INPUT : scale - scale for decay correcting image @@ -1565,7 +1590,7 @@ return FALSE; } - + /* ----------------------------- MNI Header ----------------------------------- @NAME : decay_correction @INPUT : scan_time - time of beginning of sample diff --git a/conversion/ecattominc/machine_indep.c b/conversion/ecattominc/machine_indep.c new file mode 100644 --- /dev/null +++ b/conversion/ecattominc/machine_indep.c @@ -0,0 +1,195 @@ +#include +#include +#include + +void get_short_value(const void *from, void *to) { + short int short_value; + + (void) memcpy(&short_value, from, sizeof(short int)); + *(short int *)to = ntohs(short_value); +} + +void get_long_value(const void *from, void *to) { + long int long_value; + + (void) memcpy(&long_value, from, sizeof(long int)); + *(long int *)to = ntohl(long_value); +} +/* from vax_conversion.c -Copyright 1993 Peter Neelin */ +/* ----------------------------- MNI Header ----------------------------------- +@NAME : vax_conversions.c +@DESCRIPTION: File containing routines to convert machine values to vax format + values. +@METHOD : +@CREATED : December 10, 1992 (Peter Neelin) +@MODIFIED : + * $Log: machine_indep.c,v $ + * Revision 6.1.2.1 2005-02-15 19:59:54 bert + * Initial checkin on 1.X branch + * + * Revision 6.1 2005/01/19 19:46:28 bert + * Changes from Anthonin Reilhac + * + * Revision 6.2 1999/10/19 15:57:18 neelin + * Fixed log message containing log substitution + * + * Revision 6.1 1999/10/19 14:45:15 neelin + * Fixed Log subsitutions for CVS + * + * Revision 6.0 1997/09/12 13:23:41 neelin + * Release of minc version 0.6 + * + * Revision 5.0 1997/08/21 13:24:41 neelin + * Release of minc version 0.5 + * + * Revision 4.0 1997/05/07 20:00:50 neelin + * Release of minc version 0.4 + * + * Revision 3.0 1995/05/15 19:31:35 neelin + * Release of minc version 0.3 + * + * Revision 2.0 1994/09/28 10:34:32 neelin + * Release of minc version 0.2 + * + * Revision 1.5 94/09/28 10:34:18 neelin + * Pre-release + * + * Revision 1.4 93/08/04 13:04:01 neelin + * Added RCS Log to keep track of modifications in source + * +@COPYRIGHT : + Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre, + Montreal Neurological Institute, McGill University. + Permission to use, copy, modify, and distribute this + software and its documentation for any purpose and without + fee is hereby granted, provided that the above copyright + notice appear in all copies. The author and McGill University + make no representations about the suitability of this + software for any purpose. It is provided "as is" without + express or implied warranty. +---------------------------------------------------------------------------- */ + +#ifndef lint +static char rcsid[]="$Header: /private-cvsroot/minc/conversion/ecattominc/machine_indep.c,v 6.1.2.1 2005-02-15 19:59:54 bert Exp $"; +#endif + +/* ----------------------------- MNI Header ----------------------------------- +@NAME : get_vax_short +@INPUT : nvals - number of values to convert + vax_value - pointer to array of shorts in vax format +@OUTPUT : mach_value - pointer to array of shorts in current machine format +@RETURNS : (nothing) +@DESCRIPTION: Converts vax short integers to short integers in the format of + the current machine. +@METHOD : +@GLOBALS : (none) +@CALLS : memcpy +@CREATED : December 10, 1992. +@MODIFIED : +---------------------------------------------------------------------------- */ +void get_vax_short(int nvals, void *vax_value, short *mach_value) +{ + int i; + char *ptr1, *ptr2, v0, v1; + +#ifdef vax + memcpy((void *) mach_value, vax_value, nvals*sizeof(short)); +#else + ptr1 = (char *) vax_value; + ptr2 = (char *) mach_value; + for (i=0; i