Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

file_tool.h File Reference

Go to the source code of this file.


Data Structures

struct  ge_extras
struct  ge_header_info
struct  ge_off
struct  param_t

Defines

#define MAX_STR_LEN   1024
#define MOD_INVALID   -1
#define MOD_STR   0
#define MOD_CHAR   1
#define MOD_U1   21
#define MOD_S1   22
#define MOD_U2   23
#define MOD_S2   24
#define MOD_U4   25
#define MOD_S4   26
#define MOD_F4   30
#define MOD_F8   31
#define USE_SHORT   0
#define USE_LONG   1
#define USE_VERSION   2
#define USE_GE   3
#define USE_HISTORY   4
#define GE_NONE   0
#define GE_ALL   0xff
#define GE_HEADER   0x01
#define GE_EXTRAS   0x02
#define GE_UV17   0x10
#define GE_OFF   0x20
#define NDISP_NONE   0
#define NDISP_INT2   0x01
#define NDISP_INT4   0x02
#define NDISP_REAL4   0x04
#define NDISP_ALL   0xff
#define CHECK_NULL_STR(str)   ( str ? str : "(nil)" )

Functions

int attack_files (param_t *p)
int check_mod_type (char *name)
int check_usage (int argc, char *argv[])
int disp_numeric_data (char *data, param_t *p, FILE *fp)
int disp_param_data (param_t *p)
int mtype_size (int type)
int read_ge_header (char *pathname, ge_header_info *hi, ge_extras *E, ge_off *off)
int process_file (char *pathname, param_t *p)
int process_ge (char *pathname, param_t *p)
int process_ge4 (char *pathname, param_t *p)
int set_params (param_t *p, int argc, char *argv[])
int help_full (char *prog)
int help_ge_structs (char *prog)
int usage (char *prog, int level)
int write_data_to_file (FILE *fp, char *filename, param_t *p)
unsigned long THD_filesize (char *pathname)
int disp_ge_offsets (char *info, ge_off *D)
int r_idisp_ge_extras (char *info, ge_extras *E)
int r_idisp_ge_header_info (char *info, ge_header_info *I)

Define Documentation

#define CHECK_NULL_STR str       ( str ? str : "(nil)" )
 

Definition at line 36 of file file_tool.h.

#define GE_ALL   0xff
 

Definition at line 24 of file file_tool.h.

Referenced by set_params().

#define GE_EXTRAS   0x02
 

Definition at line 26 of file file_tool.h.

Referenced by process_ge(), and set_params().

#define GE_HEADER   0x01
 

Definition at line 25 of file file_tool.h.

Referenced by process_ge(), and set_params().

#define GE_NONE   0
 

Definition at line 23 of file file_tool.h.

#define GE_OFF   0x20
 

Definition at line 28 of file file_tool.h.

Referenced by process_ge(), and set_params().

#define GE_UV17   0x10
 

Definition at line 27 of file file_tool.h.

Referenced by process_ge(), and set_params().

#define MAX_STR_LEN   1024
 

Definition at line 2 of file file_tool.h.

Referenced by set_params().

#define MOD_CHAR   1
 

Definition at line 6 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), set_params(), and write_data_to_file().

#define MOD_F4   30
 

Definition at line 13 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_F8   31
 

Definition at line 14 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_INVALID   -1
 

Definition at line 4 of file file_tool.h.

Referenced by check_mod_type(), and set_params().

#define MOD_S1   22
 

Definition at line 8 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_S2   24
 

Definition at line 10 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_S4   26
 

Definition at line 12 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_STR   0
 

Definition at line 5 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), set_params(), and write_data_to_file().

#define MOD_U1   21
 

Definition at line 7 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_U2   23
 

Definition at line 9 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define MOD_U4   25
 

Definition at line 11 of file file_tool.h.

Referenced by check_mod_type(), mtype_size(), and write_data_to_file().

#define NDISP_ALL   0xff
 

Definition at line 34 of file file_tool.h.

#define NDISP_INT2   0x01
 

Definition at line 31 of file file_tool.h.

Referenced by disp_numeric_data(), and set_params().

#define NDISP_INT4   0x02
 

Definition at line 32 of file file_tool.h.

Referenced by disp_numeric_data(), and set_params().

#define NDISP_NONE   0
 

Definition at line 30 of file file_tool.h.

#define NDISP_REAL4   0x04
 

Definition at line 33 of file file_tool.h.

Referenced by disp_numeric_data(), and set_params().

#define USE_GE   3
 

Definition at line 19 of file file_tool.h.

Referenced by set_params(), and usage().

#define USE_HISTORY   4
 

Definition at line 20 of file file_tool.h.

#define USE_LONG   1
 

Definition at line 17 of file file_tool.h.

#define USE_SHORT   0
 

Definition at line 16 of file file_tool.h.

#define USE_VERSION   2
 

Definition at line 18 of file file_tool.h.


Function Documentation

int attack_files param_t   p
 

Definition at line 170 of file file_tool.c.

References param_t::flist, param_t::ge4_disp, param_t::ge_disp, param_t::num_files, p, process_file(), process_ge(), and process_ge4().

Referenced by main().

00171 {
00172     int fc, rv;
00173 
00174     for ( fc = 0; fc < p->num_files; fc++ )
00175     {
00176         if ( p->ge_disp )
00177         {
00178             if ( (rv = process_ge( p->flist[fc], p )) != 0 )
00179                 return rv;
00180         }
00181         else if ( p->ge4_disp )
00182         {
00183             if ( (rv = process_ge4( p->flist[fc], p )) != 0 )
00184                 return rv;
00185         }
00186         else if ( ( rv = process_file( p->flist[fc], p) ) != 0 )
00187             return rv;
00188     }
00189 
00190     return 0;
00191 }

int check_mod_type char *    name
 

Definition at line 794 of file file_tool.c.

References MOD_CHAR, MOD_F4, MOD_F8, MOD_INVALID, MOD_S1, MOD_S2, MOD_S4, MOD_STR, MOD_U1, MOD_U2, MOD_U4, and name.

Referenced by set_params().

00795 {
00796     /* character mods */
00797     if ( ! strncmp(name, "str", 3) )
00798         return MOD_STR; /* this is default */
00799     if ( ! strncmp(name, "val",  3) || ! strncmp(name, "char", 4) )
00800         return MOD_CHAR;
00801 
00802     /* integral mods */
00803     if ( ! strncmp(name, "uint1", 5) )
00804         return MOD_U1;
00805     if ( ! strncmp(name, "sint1", 5) )
00806         return MOD_S1;
00807     if ( ! strncmp(name, "uint2", 5) )
00808         return MOD_U2;
00809     if ( ! strncmp(name, "sint2", 5) )
00810         return MOD_S2;
00811     if ( ! strncmp(name, "uint4", 5) )
00812         return MOD_U4;
00813     if ( ! strncmp(name, "sint4", 5) )
00814         return MOD_S4;
00815 
00816     /* real mods */
00817     if ( ! strncmp(name, "float4", 6) )
00818         return MOD_F4;
00819     if ( ! strncmp(name, "float8", 6) )
00820         return MOD_F8;
00821 
00822     return MOD_INVALID;
00823 }

int check_usage int    argc,
char *    argv[]
 

int disp_ge_offsets char *    info,
ge_off   D
 

Definition at line 1573 of file file_tool.c.

References ge_off::dx, ge_off::dy, ge_off::dz, ge_off::nx, ge_off::ny, ge_off::te, ge_off::tr, ge_off::uv17, and ge_off::xyz.

Referenced by process_ge().

01574 {
01575     if ( info )
01576         fputs( info, stdout );
01577 
01578     if ( D == NULL )
01579     {
01580         printf( "disp_ge_offsets: D == NULL" );
01581         return -1;
01582     }
01583 
01584     printf( " ge_off at %p :\n"
01585             "    nx, ny, uv17 = %d, %d, %d\n"
01586             "    dx, dy, dz   = %d, %d, %d\n"
01587             "    tr, te, xyz  = %d, %d, %d\n",
01588             D, D->nx, D->ny, D->uv17,
01589             D->dx, D->dy, D->dz,
01590             D->tr, D->te, D->xyz
01591           );
01592 
01593     return 0;
01594 }

int disp_numeric_data char *    data,
param_t   p,
FILE *    fp
 

Definition at line 1402 of file file_tool.c.

References c, param_t::length, param_t::ndisp, NDISP_INT2, NDISP_INT4, NDISP_REAL4, param_t::offset, p, param_t::swap, swap_2(), and swap_4().

Referenced by process_file().

01403 {
01404     int c;
01405 
01406     if ( data == NULL || fp == NULL )
01407     {
01408         fprintf( stderr, "** error: bad params to DND '%p,%p'\n", data, fp );
01409         return -1;
01410     }
01411 
01412     if ( p->length <= 0 || p->ndisp == 0 )
01413         return 0;
01414 
01415     /* print out shorts */
01416     if ( p->ndisp & NDISP_INT2 )
01417     {
01418         short * sp = (short *)data;
01419 
01420         fprintf( fp, "0x%4x : ", (unsigned int)p->offset );
01421         for ( c = 0; c < p->length/2; c++, sp++ )
01422         {
01423             if ( p->swap )
01424                 swap_2( sp );
01425             fprintf( fp, "%d ", *sp );
01426         }
01427         fputc( '\n', fp );
01428     }
01429 
01430     /* print out ints */
01431     if ( p->ndisp & NDISP_INT4 )
01432     {
01433         int * ip = (int *)data;
01434 
01435         fprintf( fp, "0x%4x : ", (unsigned int)p->offset );
01436         for ( c = 0; c < p->length/4; c++, ip++ )
01437         {
01438             if ( p->swap )
01439                 swap_4( ip );
01440             fprintf( fp, "%d ", *ip );
01441         }
01442         fputc( '\n', fp );
01443     }
01444 
01445     /* print out floats */
01446     if ( p->ndisp & NDISP_REAL4 )
01447     {
01448         float * rp = (float *)data;
01449 
01450         fprintf( fp, "0x%4x : ", (unsigned int)p->offset );
01451         for ( c = 0; c < p->length/4; c++, rp++ )
01452         {
01453             if ( p->swap )
01454                 swap_4( rp );
01455             fprintf( fp, "%f ", *rp );
01456         }
01457         fputc( '\n', fp );
01458     }
01459 
01460     return 0;
01461 }

int disp_param_data param_t   p
 

Definition at line 1469 of file file_tool.c.

References c, param_t::data_len, param_t::debug, param_t::flist, param_t::ge4_disp, param_t::ge_disp, param_t::length, param_t::mod_data, param_t::mod_type, param_t::modify, param_t::ndisp, param_t::num_files, param_t::offset, p, param_t::quiet, and param_t::swap.

Referenced by set_params().

01470 {
01471     if ( ! p )
01472         return -1;
01473 
01474     printf( "num_files, flist         : %d, %p\n"
01475             "debug, data_len          : %d, %d\n"
01476             "ge_disp, ge4_disp, ndisp : 0x%x, 0x%x, 0x%x\n"
01477             "\n"
01478             "swap, modify, mod_type   : %d, %d, %d\n"
01479             "offset, length, quiet    : %ld, %d, %d\n"
01480             "mod_data                 : %s\n"
01481             "\n",
01482             p->num_files, p->flist, p->debug, p->data_len,
01483             p->ge_disp, p->ge4_disp, p->ndisp, p->swap, p->modify,
01484             p->mod_type, p->offset, p->length, p->quiet,
01485             CHECK_NULL_STR(p->mod_data)
01486           );
01487 
01488     if ( p->debug > 1 )
01489     {
01490         int c;
01491 
01492         printf( "file list: " );
01493         for ( c = 0; c < p->num_files; c ++ )
01494             printf( "'%s' ", p->flist[c] );
01495         printf( "\n" );
01496     }
01497 
01498     return 0;
01499 }

int help_full char *    prog
 

Definition at line 920 of file file_tool.c.

References VERSION.

Referenced by usage().

00921 {
00922     printf(
00923         "\n"
00924         "%s - display or modify sections of a file\n"
00925         "\n"
00926         "    This program can be used to display or edit data in arbitrary\n"
00927         "    files.  If no '-mod_data' option is provided (with DATA), it\n"
00928         "    is assumed the user wishes only to display the specified data\n"
00929         "    (using both '-offset' and '-length', or using '-ge_XXX').\n"
00930         "\n"
00931         "  usage: %s [options] -infiles file1 file2 ...\n"
00932         "\n"
00933         "  examples:\n"
00934         "\n"
00935         "   ----- help examples -----\n"
00936         "\n"
00937         "   1. get detailed help:\n"
00938         "\n"
00939         "      %s -help\n"
00940         "\n"
00941         "   2. get descriptions of GE struct elements:\n"
00942         "\n"
00943         "      %s -help_ge\n"
00944         "\n"
00945         "   ----- GEMS 4.x and 5.x display examples -----\n"
00946         "\n"
00947         "   3. display GE header and extras info for file I.100:\n"
00948         "\n"
00949         "      %s -ge_all -infiles I.100\n"
00950         "\n"
00951         "   4. display GEMS 4.x series and image headers for file I.100:\n"
00952         "\n"
00953         "      %s -ge4_all -infiles I.100\n"
00954         "\n"
00955         "   5. display run numbers for every 100th I-file in this directory\n"
00956         "\n"
00957         "      %s -ge_uv17 -infiles I.?42\n"
00958         "      %s -ge_run  -infiles I.?42\n"
00959         "\n"
00960         "   ----- general value display examples -----\n"
00961         "\n"
00962         "   6. display the 32 characters located 100 bytes into each file:\n"
00963         "\n"
00964         "      %s -offset 100 -length 32 -infiles file1 file2\n"
00965         "\n"
00966         "   7. display the 8 4-byte reals located 100 bytes into each file:\n"
00967         "\n"
00968         "      %s -disp_real4 -offset 100 -length 32 -infiles file1 file2\n"
00969         "\n"
00970         "   ----- character modification examples -----\n"
00971         "\n"
00972         "   8. in each file, change the 8 characters at 2515 to 'hi there':\n"
00973         "\n"
00974         "      %s -mod_data \"hi there\" -offset 2515 -length 8 -infiles I.*\n"
00975         "\n"
00976         "   9. in each file, change the 21 characters at 2515 to all 'x's\n"
00977         "      (and print out extra debug info)\n"
00978         "\n"
00979         "      %s -debug 1 -mod_data x -mod_type val -offset 2515 \\\n"
00980         "                -length 21 -infiles I.*\n"
00981         "\n"
00982         "   ----- raw number modification examples -----\n"
00983         "\n"
00984         "  10. in each file, change the 3 short integers starting at position\n"
00985         "      2508 to '2 -419 17'\n"
00986         "\n"
00987         "      %s -mod_data '2 -419 17' -mod_type sint2 -offset 2508 \\\n"
00988         "                -length 6 -infiles I.*\n"
00989         "\n"
00990         "  11. in each file, change the 3 binary floats starting at position\n"
00991         "      2508 to '-83.4 2 17' (and set the next 8 bytes to zero by\n"
00992         "      setting the length to 20, instead of just 12).\n"
00993         "\n"
00994         "      %s -mod_data '-83.4 2 17' -mod_type float4 -offset 2508 \\\n"
00995         "                -length 20 -infiles I.*\n"
00996         "\n"
00997         "  12. in each file, change the 3 binary floats starting at position\n"
00998         "      2508 to '-83.4 2 17', and apply byte swapping\n"
00999         "\n"
01000         "      %s -mod_data '-83.4 2 17' -mod_type float4 -offset 2508 \\\n"
01001         "                -length 12 -swap_bytes -infiles I.*\n"
01002         "\n"
01003         "  notes:\n"
01004         "\n"
01005         "    o  Use of '-infiles' is required.\n"
01006         "    o  Use of '-length' or a GE information option is required.\n"
01007         "    o  As of this version, only modification with text is supported.\n"
01008         "       Editing binary data is coming soon to a workstation near you.\n"
01009         "\n"
01010         "  special options:\n"
01011         "\n"
01012         "    -help              : show this help information\n"
01013         "                       : e.g. -help\n"
01014         "\n"
01015         "    -version           : show version information\n"
01016         "                       : e.g. -version\n"
01017         "\n"
01018         "    -hist              : show the program's modification history\n"
01019         "\n"
01020         "    -debug LEVEL       : print extra info along the way\n"
01021         "                       : e.g. -debug 1\n"
01022         "                       : default is 0, max is 2\n"
01023         "\n"
01024         "  required 'options':\n"
01025         "\n"
01026         "    -infiles f1 f2 ... : specify input files to print from or modify\n"
01027         "                       : e.g. -infiles file1\n"
01028         "                       : e.g. -infiles I.*\n"
01029         "\n"
01030         "          Note that '-infiles' should be the final option.  This is\n"
01031         "          to allow the user an arbitrary number of input files.\n"
01032         "\n"
01033         "  GE info options:\n"
01034         "\n"
01035         "      -ge_all          : display GE header and extras info\n"
01036         "      -ge_header       : display GE header info\n"
01037         "      -ge_extras       : display extra GE image info\n"
01038         "      -ge_uv17         : display the value of uv17 (the run #)\n"
01039         "      -ge_run          : (same as -ge_uv17)\n"
01040         "      -ge_off          : display file offsets for various fields\n"
01041         "\n"
01042         "  GEMS 4.x info options:\n"
01043         "\n"
01044         "      -ge4_all         : display GEMS 4.x series and image headers\n"
01045         "      -ge4_image       : display GEMS 4.x image header\n"
01046         "      -ge4_series      : display GEMS 4.x series header\n"
01047         "      -ge4_study       : display GEMS 4.x study header\n"
01048         "\n"
01049         "  raw ascii options:\n"
01050         "\n"
01051         "    -length LENGTH     : specify the number of bytes to print/modify\n"
01052         "                       : e.g. -length 17\n"
01053         "\n"
01054         "          This includes numbers after the conversion to binary.  So\n"
01055         "          if -mod_data is '2 -63 186', and -mod_type is 'sint2' (or\n"
01056         "          signed shorts), then 6 bytes will be written (2 bytes for\n"
01057         "          each of 3 short integers).\n"
01058         "\n"
01059         "       ** Note that if the -length argument is MORE than what is\n"
01060         "          needed to write the numbers out, the remaind of the length\n"
01061         "          bytes will be written with zeros.  If '17' is given for\n"
01062         "          the length, and 3 short integers are given as data, there \n"
01063         "          will be 11 bytes of 0 written after the 6 bytes of data.\n"
01064         "\n"
01065         "    -mod_data DATA     : specify a string to change the data to\n"
01066         "                       : e.g. -mod_data hello\n"
01067         "                       : e.g. -mod_data '2 -17.4 649'\n"
01068         "                       : e.g. -mod_data \"change to this string\"\n"
01069         "\n"
01070         "          This is the data that will be writting into the modified\n"
01071         "          file.  If the -mod_type is 'str' or 'char', then the\n"
01072         "          output data will be those characters.  If the -mod_type\n"
01073         "          is any other (i.e. a binary numerical format), then the\n"
01074         "          output will be the -mod_data, converted from numerical\n"
01075         "          text to binary.\n"
01076         "\n"
01077         "       ** Note that a list of numbers must be contained in quotes,\n"
01078         "          so that it will be processed as a single parameter.\n"
01079         "\n"
01080         "    -mod_type TYPE     : specify the data type to write to the file\n"
01081         "                       : e.g. -mod_type string\n"
01082         "                       : e.g. -mod_type sint2\n"
01083         "                       : e.g. -mod_type float4\n"
01084         "                       : default is 'str'\n"
01085         "\n"
01086         "        TYPE can be one of:\n"
01087         "\n"
01088         "          str       : perform a string substitution\n"
01089         "          char, val : perform a (repeated?) character substitution\n"
01090         "          uint1     : single byte unsigned int   (binary write)\n"
01091         "          sint1     : single byte   signed int   (binary write)\n"
01092         "          uint2     : two    byte unsigned int   (binary write)\n"
01093         "          sint2     : two    byte   signed int   (binary write)\n"
01094         "          uint4     : four   byte unsigned int   (binary write)\n"
01095         "          sint4     : four   byte   signed int   (binary write)\n"
01096         "          float4    : four   byte floating point (binary write)\n"
01097         "          float8    : eight  byte floating point (binary write)\n"
01098         "\n"
01099         "          If 'str' is used, which is the default action, the data is\n"
01100         "          replaced by the contents of the string DATA (from the\n"
01101         "          '-mod_data' option).\n"
01102         "\n"
01103         "          If 'char' is used, then LENGTH bytes are replaced by the\n"
01104         "          first character of DATA, repeated LENGTH times.\n"
01105         "\n"
01106         "          For any of the others, the list of numbers found in the\n"
01107         "          -mod_data option will be written in the supplied binary\n"
01108         "          format.  LENGTH must be large enough to accomodate this\n"
01109         "          list.  And if LENGTH is higher, the output will be padded\n"
01110         "          with zeros, to fill to the requesed length.\n"
01111         "\n"
01112         "    -offset OFFSET     : use this offset into each file\n"
01113         "                       : e.g. -offset 100\n"
01114         "                       : default is 0\n"
01115         "\n"
01116         "          This is the offset into each file for the data to be\n"
01117         "          read or modified.\n"
01118         "\n"
01119         "    -quiet             : do not output header information\n"
01120         "\n"
01121         "  numeric options:\n"
01122         "\n"
01123         "    -disp_int2         : display 2-byte integers\n"
01124         "                       : e.g. -disp_int2\n"
01125         "\n"
01126         "    -disp_int4         : display 4-byte integers\n"
01127         "                       : e.g. -disp_int4\n"
01128         "\n"
01129         "    -disp_real4        : display 4-byte real numbers\n"
01130         "                       : e.g. -disp_real4\n"
01131         "\n"
01132         "    -swap_bytes        : use byte-swapping on numbers\n"
01133         "                       : e.g. -swap_bytes\n"
01134         "\n"
01135         "          If this option is used, then byte swapping is done on any\n"
01136         "          multi-byte numbers read from or written to the file.\n"
01137         "\n"
01138         "  - R Reynolds, version: %s, compiled: %s\n"
01139         "\n",
01140         prog, prog,
01141         prog, prog, prog, prog, prog, prog, prog, prog, prog,
01142         prog, prog, prog, prog,
01143         VERSION, __DATE__
01144         );
01145 
01146     return 0;
01147 }

int help_ge_structs char *    prog
 

Definition at line 877 of file file_tool.c.

Referenced by usage().

00878 {
00879     printf( "------------------------------------------------------------\n"
00880             "These are descriptions of the elements in the GE\n"
00881             "data structures used by '%s'.  Most elements\n"
00882             "correspond to a field in the image file header.\n"
00883             "\n"
00884             "These fields are shown when running '%s'\n"
00885             "with any of the options:\n"
00886             "   '-ge_header', '-ge_extras', or '-ge_all'.\n"
00887             /* taken from Ifile.c */
00888             "----------------------------------------\n"
00889             "ge_header_info struct:\n"
00890             "\n"
00891             "    good     : is this a valid GE image file\n"
00892             "    nx,ny    : dimensions of image in voxels\n"
00893             "    uv17     : run number (user variable 17)\n"
00894             "    dx,dy,dz : directional deltas - distances between voxels\n"
00895             "    zoff     : location of image in z direction\n"
00896             "    tr,te    : TR and TE timings\n"
00897             "    orients  : orientation string for image\n"
00898             "----------------------------------------\n"
00899             /* taken from mri_read.c */
00900             "ge_extras struct:\n"
00901             "\n"
00902             "    bpp      : bytes per pixel (file_size = nx * ny * bpp)\n"
00903             "    cflag    : compression flag (here, 1 means NOT compressed)\n"
00904             "    hdroff   : offset of image header (from beginning of file)\n"
00905             "    skip     : offset of image data   (from beginning of file)\n"
00906             "    swap     : is byte swapping performed?\n"
00907             "    xyzX     : coordinate box containing image\n"
00908             "------------------------------------------------------------\n"
00909             "\n", prog, prog
00910           );
00911 
00912     return 0;
00913 }

int mtype_size int    type
 

Definition at line 492 of file file_tool.c.

References MOD_CHAR, MOD_F4, MOD_F8, MOD_S1, MOD_S2, MOD_S4, MOD_STR, MOD_U1, MOD_U2, and MOD_U4.

Referenced by write_data_to_file().

00493 {
00494     if ( type == MOD_STR  ) return 1;
00495     if ( type == MOD_CHAR ) return 1;
00496     if ( type == MOD_U1   ) return 1;
00497     if ( type == MOD_S1   ) return 1;
00498 
00499     if ( type == MOD_U2   ) return 2;
00500     if ( type == MOD_S2   ) return 2;
00501 
00502     if ( type == MOD_U4   ) return 4;
00503     if ( type == MOD_S4   ) return 4;
00504 
00505     if ( type == MOD_F4   ) return 4;
00506     if ( type == MOD_F8   ) return 8;
00507 
00508     return -1;
00509 }

int process_file char *    pathname,
param_t   p
 

Definition at line 283 of file file_tool.c.

References calloc, param_t::debug, disp_numeric_data(), param_t::length, param_t::mod_data, param_t::modify, param_t::ndisp, param_t::offset, p, param_t::quiet, and write_data_to_file().

Referenced by attack_files().

00284 {
00285     FILE        * fp;
00286     static char * fdata = NULL;
00287     int           nbytes;
00288 
00289     if ( (fp = fopen( filename, "r+" )) == NULL )
00290     {
00291         fprintf( stderr, "failure: cannot open <%s> for 'rw'\n", filename );
00292         return -1;
00293     }
00294 
00295     if ( fdata == NULL )
00296     {
00297         fdata = (char*) calloc( p->length, sizeof(char) );
00298         if ( fdata == NULL )
00299         {
00300             fprintf( stderr, "failure: cannot allocate %d bytes for data\n",
00301                      p->length );
00302             return -1;
00303         }
00304     }
00305 
00306     if ( fseek( fp, p->offset, SEEK_SET ) )
00307     {
00308         fprintf( stderr, "failure: cannot seek to <%ld> in file '%s'\n",
00309                  p->offset, filename );
00310         fclose( fp );
00311         return -1;
00312     }
00313 
00314     if ( (nbytes = fread( fdata, 1, p->length, fp )) != p->length )
00315     {
00316         fprintf( stderr, "failure: read only %d of %d bytes from file '%s'\n",
00317                  nbytes, p->length, filename );
00318         fclose( fp );
00319         return -1;
00320     }
00321 
00322     /* display file contents */
00323     if ( !p->modify || p->debug )
00324     {
00325         if ( ! p->quiet && ! p->ndisp )
00326             printf( "<%s> : '", filename );
00327 
00328         /* handle the numeric display */
00329         if ( p->ndisp )
00330         {
00331             if ( disp_numeric_data( fdata, p, stdout ) )
00332             {
00333                 fclose( fp );
00334                 return -1;
00335             }
00336         }
00337         else if ( (nbytes = fwrite(fdata, 1, p->length, stdout)) != p->length )
00338         {
00339             fprintf( stderr, "\nfailure: wrote only %d of %d bytes to '%s'\n",
00340                      nbytes, p->length, "stdout" );
00341             fclose( fp );
00342             return -1;
00343         }
00344         if ( ! p->quiet && ! p->ndisp )
00345             puts( "'" );        /* single quote plus newline */
00346     }
00347 
00348     if ( p->modify )  /* if writing back to file */
00349     {
00350         if ( fseek( fp, p->offset, SEEK_SET ) )
00351         {
00352             fprintf( stderr, "failure: cannot re-seek to <%ld> in file '%s'\n",
00353                      p->offset, filename );
00354             fclose( fp );
00355             return -1;
00356         }
00357 
00358         if ( (nbytes = write_data_to_file( fp, filename, p ) ) < 0 )
00359         {
00360             fclose( fp );
00361             return -1;
00362         }
00363 
00364         if ( p->debug > 0 )
00365         {
00366             printf( "wrote '%s' (%d bytes) to file '%s', position %ld\n",
00367                     p->mod_data, p->length, filename, p->offset );
00368         }
00369     }
00370 
00371     fclose( fp );
00372 
00373     return 0;
00374 }

int process_ge char *    pathname,
param_t   p
 

Definition at line 235 of file file_tool.c.

References param_t::debug, disp_ge_offsets(), E, param_t::ge_disp, GE_EXTRAS, GE_HEADER, GE_OFF, GE_UV17, p, r_idisp_ge_extras(), r_idisp_ge_header_info(), read_ge_header(), and ge_header_info::uv17.

Referenced by attack_files().

00236 {
00237     ge_header_info H;
00238     ge_extras      E;
00239     ge_off         off;
00240     int            rv;
00241 
00242     rv = read_ge_header( filename, &H, &E, &off );
00243 
00244     if ( rv != 0 )
00245     {
00246         if ( p->ge_disp )  /* if we are here to display - state results */
00247         {
00248             printf( "%s : GE header failure : %d\n", filename, rv );
00249             return 0;  /* don't fail out */
00250         }
00251         else
00252             return -1;     /* else, just return the results */
00253     }
00254 
00255     if ( (p->debug > 1) || (p->ge_disp & GE_HEADER) )
00256         r_idisp_ge_header_info( filename, &H );
00257 
00258     if ( (p->debug > 1) || (p->ge_disp & GE_EXTRAS ) )
00259         r_idisp_ge_extras( filename, &E );
00260 
00261     if ( p->ge_disp & GE_OFF )
00262         disp_ge_offsets( filename, &off );
00263 
00264     if ( p->ge_disp & GE_UV17 )
00265         printf( "%s : run # %d\n", filename, H.uv17 );
00266 
00267     return 0;
00268 }

int process_ge4 char *    pathname,
param_t   p
 

Definition at line 199 of file file_tool.c.

References param_t::debug, param_t::ge4_disp, GE4_DISP_IMAGE, GE4_DISP_SERIES, GE4_DISP_STUDY, ge4_read_header(), idisp_ge4_image_header(), idisp_ge4_series_header(), idisp_ge4_study_header(), ge4_header::im_h, p, ge4_header::ser_h, and ge4_header::std_h.

Referenced by attack_files().

00200 {
00201     ge4_header H;
00202     int        rv;
00203 
00204     rv = ge4_read_header( &H, filename, 0 );
00205 
00206     if ( rv != 0 )
00207     {
00208         if ( p->ge4_disp )      /* then display the bad result */
00209         {
00210             printf( "%s : GEMS 4.x header failure : %d\n", filename, rv );
00211             return 0;
00212         }
00213         else                    /* else just return it */
00214             return -1;
00215     }
00216 
00217     if ( (p->debug > 1) || (p->ge4_disp & GE4_DISP_STUDY) )
00218         idisp_ge4_study_header( filename, &H.std_h );
00219 
00220     if ( (p->debug > 1) || (p->ge4_disp & GE4_DISP_SERIES) )
00221         idisp_ge4_series_header( filename, &H.ser_h );
00222 
00223     if ( (p->debug > 1) || (p->ge4_disp & GE4_DISP_IMAGE) )
00224         idisp_ge4_image_header( filename, &H.im_h );
00225 
00226     return 0;
00227 }

int r_idisp_ge_extras char *    info,
ge_extras   E
 

Definition at line 1507 of file file_tool.c.

References ge_extras::bpp, ge_extras::cflag, E, ge_extras::hdroff, ge_extras::skip, ge_extras::swap, and ge_extras::xyz.

Referenced by process_ge().

01508 {
01509     if ( info )
01510         fputs( info, stdout );
01511 
01512     if ( E == NULL )
01513     {
01514         printf( "r_idisp_ge_extras: E == NULL" );
01515         return -1;
01516     }
01517 
01518     printf( " ge_extras at %p :\n"
01519             "    bpp              = %d\n"
01520             "    cflag            = %d\n"
01521             "    hdroff           = %d\n"
01522             "    skip             = %d\n"
01523             "    swap             = %d\n"
01524             "    (xyz0,xyz1,xyz2) = (%f,%f,%f)\n"
01525             "    (xyz3,xyz4,xyz5) = (%f,%f,%f)\n"
01526             "    (xyz6,xyz7,xyz8) = (%f,%f,%f)\n",
01527             E, E->bpp, E->cflag, E->hdroff, E->skip, E->swap,
01528             E->xyz[0], E->xyz[1], E->xyz[2],
01529             E->xyz[3], E->xyz[4], E->xyz[5],
01530             E->xyz[6], E->xyz[7], E->xyz[8]
01531           );
01532     return 0;
01533 }

int r_idisp_ge_header_info char *    info,
ge_header_info   I
 

Definition at line 1540 of file file_tool.c.

References ge_header_info::dx, ge_header_info::dy, ge_header_info::dz, ge_header_info::good, ge_header_info::nx, ge_header_info::ny, ge_header_info::orients, ge_header_info::te, ge_header_info::tr, ge_header_info::uv17, and ge_header_info::zoff.

Referenced by process_ge().

01541 {
01542     if ( info )
01543         fputs( info, stdout );
01544 
01545     if ( I == NULL )
01546     {
01547         printf( "r_idisp_ge_header_info: I == NULL" );
01548         return -1;
01549     }
01550 
01551     printf( " ge_header_info at %p :\n"
01552             "    good        = %d\n"
01553             "    (nx,ny)     = (%d,%d)\n"
01554             "    uv17        = %d\n"
01555             "    (dx,dy,dz)  = (%f,%f,%f)\n"
01556             "    zoff        = %f\n"
01557             "    (tr,te)     = (%f,%f)\n"
01558             "    orients     = %8s\n",
01559             I, I->good, I->nx, I->ny, I->uv17,
01560             I->dx, I->dy, I->dz, I->zoff, I->tr, I->te,
01561             CHECK_NULL_STR(I->orients)
01562           );
01563 
01564     return 0;
01565 }

int read_ge_header char *    pathname,
ge_header_info   hi,
ge_extras   E,
ge_off   off
 

Definition at line 1184 of file file_tool.c.

References abs, ge_extras::bpp, ge_extras::cflag, ge_header_info::dx, ge_off::dx, ge_header_info::dy, ge_off::dy, ge_header_info::dz, ge_off::dz, E, ge_header_info::good, ge_extras::hdroff, L, ge_off::nx, ge_header_info::nx, ge_off::ny, ge_header_info::ny, ge_header_info::orients, ge_extras::skip, skip, ge_extras::swap, swap, swap_4(), ge_header_info::te, ge_off::te, THD_filesize(), ge_header_info::tr, ge_off::tr, ge_header_info::uv17, ge_off::uv17, ge_extras::xyz, ge_off::xyz, and ge_header_info::zoff.

Referenced by process_ge().

01185 {
01186    FILE *imfile ;
01187    int  length , skip , swap=0 ;
01188    char orients[8] , str[8] ;
01189    int nx , ny , bpp , cflag , hdroff ;
01190         float uv17 = -1.0;
01191         
01192    if( hi == NULL ) return -1;            /* bad */
01193    hi->good = 0 ;                       /* not good yet */
01194    if( pathname    == NULL ||
01195        pathname[0] == '\0'   ) return -1; /* bad */
01196 
01197    length = THD_filesize( pathname ) ;
01198    if( length < 1024 ) return -1;         /* bad */
01199 
01200    imfile = fopen( pathname , "r" ) ;
01201    if( imfile == NULL ) return -1;        /* bad */
01202 
01203    strcpy(str,"JUNK") ;     /* initialize string */
01204    fread(str,1,4,imfile) ;  /* check for "IMGF" at start of file */
01205 
01206    if( str[0]!='I' || str[1]!='M' || str[2]!='G' || str[3]!='F' ){ /* bad */
01207       fclose(imfile) ; return -2;
01208    }
01209 
01210    /*-- read next 5 ints (after the "IMGF" string) --*/
01211 
01212    fread( &skip , 4,1, imfile ) ; /* offset into file of image data */
01213    fread( &nx   , 4,1, imfile ) ; /* x-size */
01214    fread( &ny   , 4,1, imfile ) ; /* y-size */
01215    fread( &bpp  , 4,1, imfile ) ; /* bits per pixel (should be 16) */
01216    fread( &cflag, 4,1, imfile ) ; /* compression flag (1=uncompressed)*/
01217 
01218         /*-- check if nx is funny --*/
01219 
01220    if( nx < 0 || nx > 8192 ){      /* have to byte swap these 5 ints */
01221      swap = 1 ;                    /* flag to swap data, too */
01222      swap_4(&skip); swap_4(&nx); swap_4(&ny); swap_4(&bpp); swap_4(&cflag);
01223    } else {
01224      swap = 0 ;  /* data is ordered for this CPU */
01225    }
01226    if( nx < 0 || nx > 8192 || ny < 0 || ny > 8192 ){  /* bad */
01227       fclose(imfile) ; return -1;
01228    }
01229 
01230    hi->nx = nx ;
01231    hi->ny = ny ;
01232 
01233    off->nx =  8;
01234    off->ny = 12;
01235 
01236    if( skip+2*nx*ny >  length ||               /* file is too short */
01237        skip         <= 0      ||               /* bizarre  */
01238        cflag        != 1      ||               /* data is compressed */
01239        bpp          != 16        ){
01240       fclose(imfile); return -1;    /* data is not shorts */
01241    }
01242 
01243    /*-- try to read image header data as well --*/
01244 
01245    fseek( imfile , 148L , SEEK_SET ) ; /* magic GEMS offset */
01246    fread( &hdroff , 4,1 , imfile ) ;   /* location of image header */
01247    if( swap ) swap_4(&hdroff) ;
01248 
01249    if( hdroff > 0 && hdroff+256 < length ){   /* can read from image header */
01250        float dx,dy,dz, xyz[9], zz ; int itr, ii,jj,kk ;
01251 
01252        /*-- get voxel grid sizes --*/
01253 
01254        fseek( imfile , hdroff+26 , SEEK_SET ) ;    /* dz */
01255        fread( &dz , 4,1 , imfile ) ;
01256 
01257        fseek( imfile , hdroff+50 , SEEK_SET ) ;    /* dx and dy */
01258        fread( &dx , 4,1 , imfile ) ;
01259        fread( &dy , 4,1 , imfile ) ;
01260 
01261        off->dx = hdroff+50;
01262        off->dy = hdroff+54;
01263        off->dz = hdroff+26;
01264 
01265        if( swap ){ swap_4(&dx); swap_4(&dy); swap_4(&dz); }
01266 
01267        hi->dx = dx ; hi->dy = dy ; hi->dz = dz ;
01268 
01269        /* grid orientation: from 3 sets of LPI corner coordinates: */
01270        /*   xyz[0..2] = top left hand corner of image     (TLHC)   */
01271        /*   xyz[3..5] = top right hand corner of image    (TRHC)   */
01272        /*   xyz[6..8] = bottom right hand corner of image (BRHC)   */
01273        /* GEMS coordinate orientation here is LPI                  */
01274 
01275        off->xyz = hdroff+154;
01276        fseek( imfile , hdroff+154 , SEEK_SET ) ;  /* another magic number */
01277        fread( xyz , 4,9 , imfile ) ;
01278        if( swap ){
01279           swap_4(xyz+0); swap_4(xyz+1); swap_4(xyz+2);
01280           swap_4(xyz+3); swap_4(xyz+4); swap_4(xyz+5);
01281           swap_4(xyz+6); swap_4(xyz+7); swap_4(xyz+8);
01282        }
01283 
01284        /* x-axis orientation */
01285        /* ii determines which spatial direction is x-axis  */
01286        /* and is the direction that has the biggest change */
01287        /* between the TLHC and TRHC                        */
01288 
01289        dx = fabs(xyz[3]-xyz[0]) ; ii = 1 ;
01290        dy = fabs(xyz[4]-xyz[1]) ; if( dy > dx ){ ii=2; dx=dy; }
01291        dz = fabs(xyz[5]-xyz[2]) ; if( dz > dx ){ ii=3;        }
01292        dx = xyz[ii+2]-xyz[ii-1] ; if( dx < 0. ){ ii = -ii;    }
01293        switch( ii ){
01294         case  1: orients[0]= 'L'; orients[1]= 'R'; break;
01295         case -1: orients[0]= 'R'; orients[1]= 'L'; break;
01296         case  2: orients[0]= 'P'; orients[1]= 'A'; break;
01297         case -2: orients[0]= 'A'; orients[1]= 'P'; break;
01298         case  3: orients[0]= 'I'; orients[1]= 'S'; break;
01299         case -3: orients[0]= 'S'; orients[1]= 'I'; break;
01300         default: orients[0]='\0'; orients[1]='\0'; break;
01301        }
01302 
01303        /* y-axis orientation */
01304        /* jj determines which spatial direction is y-axis  */
01305        /* and is the direction that has the biggest change */
01306        /* between the BRHC and TRHC                        */
01307 
01308        dx = fabs(xyz[6]-xyz[3]) ; jj = 1 ;
01309        dy = fabs(xyz[7]-xyz[4]) ; if( dy > dx ){ jj=2; dx=dy; }
01310        dz = fabs(xyz[8]-xyz[5]) ; if( dz > dx ){ jj=3;        }
01311        dx = xyz[jj+5]-xyz[jj+2] ; if( dx < 0. ){ jj = -jj;    }
01312        switch( jj ){
01313          case  1: orients[2] = 'L'; orients[3] = 'R'; break;
01314          case -1: orients[2] = 'R'; orients[3] = 'L'; break;
01315          case  2: orients[2] = 'P'; orients[3] = 'A'; break;
01316          case -2: orients[2] = 'A'; orients[3] = 'P'; break;
01317          case  3: orients[2] = 'I'; orients[3] = 'S'; break;
01318          case -3: orients[2] = 'S'; orients[3] = 'I'; break;
01319          default: orients[2] ='\0'; orients[3] ='\0'; break;
01320        }
01321 
01322        orients[4] = '\0' ;   /* terminate orientation string */
01323 
01324        kk = 6 - abs(ii)-abs(jj) ;   /* which spatial direction is z-axis   */
01325                                     /* where 1=LR, 2=PA, 3=IS               */
01326                                     /* (can't tell orientation from 1 slice) */
01327 
01328        zz = xyz[kk-1] ;             /* z-coordinate of this slice */
01329 
01330        hi->zoff = zz ;
01331        strcpy(hi->orients,orients) ;
01332 
01333        /*-- get TR in seconds --*/
01334 
01335        off->tr = hdroff+194;
01336        fseek( imfile , hdroff+194 , SEEK_SET ) ;
01337        fread( &itr , 4,1 , imfile ) ; /* note itr is an int */
01338        if( swap ) swap_4(&itr) ;
01339        hi->tr = 1.0e-6 * itr ;        /* itr is in microsec */
01340 
01341        /*-- get TE in milliseconds --*/
01342 
01343        off->te = hdroff+202;
01344        fseek( imfile , hdroff+202 , SEEK_SET ) ;
01345        fread( &itr , 4,1 , imfile ) ; /* itr is an int, in microsec */
01346        if( swap ) swap_4(&itr) ;
01347        hi->te = 1.0e-6 * itr ;
01348 
01349        /* zmodify: get User Variable 17, a likely indicator of a new scan,
01350         * info by S. Marrett, location from S. Inati's matlab function
01351         * GE_readHeaderImage.m
01352         */
01353 
01354         off->uv17 = hdroff+272+202;
01355         /* printf ("\nuv17 = \n"); */
01356         fseek ( imfile , hdroff+272+202, SEEK_SET ) ;
01357         fread( &uv17 , 4, 1 , imfile ) ;
01358         if( swap ) swap_4(&uv17) ;
01359         /* printf ("%d ", (int)uv17);  */
01360         hi->uv17 = (int)uv17; 
01361         /* printf ("\n"); */
01362         
01363         hi->good = 1 ;                  /* this is a good file */
01364 
01365         E->bpp    = bpp;                /* store the ge_extra info */
01366         E->cflag  = cflag;
01367         E->hdroff = hdroff;
01368         E->skip   = skip;
01369         E->swap   = swap;
01370 
01371         memcpy( E->xyz, xyz, sizeof(xyz) );
01372     } /* end of actually reading image header */
01373 
01374     fclose(imfile);
01375     return 0;
01376 }

int set_params param_t   p,
int    argc,
char *    argv[]
 

Definition at line 518 of file file_tool.c.

References argc, check_mod_type(), param_t::data_len, param_t::debug, disp_param_data(), param_t::flist, g_rep_output_data, param_t::ge4_disp, GE4_DISP_ALL, GE4_DISP_IMAGE, GE4_DISP_SERIES, GE4_DISP_STUDY, GE_ALL, param_t::ge_disp, GE_EXTRAS, GE_HEADER, GE_OFF, GE_UV17, param_t::length, MAX_STR_LEN, MOD_CHAR, param_t::mod_data, MOD_INVALID, MOD_STR, param_t::mod_type, param_t::modify, param_t::ndisp, NDISP_INT2, NDISP_INT4, NDISP_REAL4, param_t::num_files, param_t::offset, p, param_t::quiet, param_t::swap, usage(), and USE_GE.

Referenced by main().

00519 {
00520     int ac;
00521 
00522     if ( argc < 2 )
00523     {
00524         usage( argv[0], USE_SHORT );
00525         return -1;
00526     }
00527 
00528     if ( !p || !argv )
00529     {
00530         fprintf( stderr, "failure: bad params to set_params: "
00531                  "p = <%p>, ac = <%d>, av = <%p>\n",
00532                  p, argc, argv );
00533         return -1;
00534     }
00535 
00536     /* clear out param struct - this sets all default values */
00537     memset( p, 0, sizeof(*p) );
00538 
00539     for ( ac = 1; ac < argc; ac++ )
00540     {
00541         /* check for -help_ge before -help, to allow for only -h */
00542         if ( ! strncmp(argv[ac], "-help_ge", 8 ) )
00543         {
00544             usage( argv[0], USE_GE );
00545             return -1;
00546         }
00547         else if ( ! strncmp(argv[ac], "-help", 3 ) )
00548         {
00549             usage( argv[0], USE_LONG );
00550             return -1;
00551         }
00552         else if ( ! strncmp(argv[ac], "-hist", 3 ) )
00553         {
00554             usage( argv[0], USE_HISTORY );
00555             return -1;
00556         }
00557         else if ( ! strncmp(argv[ac], "-debug", 6 ) )
00558         {
00559             if ( (ac+1) >= argc )
00560             {
00561                 fputs( "missing option parameter: LEVEL\n"
00562                        "option usage: -debug LEVEL\n"
00563                        "    where LEVEL is the debug level (0,1 or 2)\n",
00564                        stderr );
00565                 return -1; 
00566             }
00567 
00568             p->debug = atoi(argv[++ac]);
00569             if ( (p->debug < 0) || (p->debug > 2) )
00570             {
00571                 fprintf( stderr, "invalid debug level <%d>\n", p->debug );
00572                 return -1;
00573             }
00574         }
00575         else if ( ! strncmp(argv[ac], "-disp_int2", 10 ) )
00576         {
00577             p->ndisp |= NDISP_INT2;
00578         }
00579         else if ( ! strncmp(argv[ac], "-disp_int4", 10 ) )
00580         {
00581             p->ndisp |= NDISP_INT4;
00582         }
00583         else if ( ! strncmp(argv[ac], "-disp_real4", 11 ) )
00584         {
00585             p->ndisp |= NDISP_REAL4;
00586         }
00587         else if ( ! strncmp(argv[ac], "-mod_data", 6 ) )
00588         {
00589             if ( (ac+1) >= argc )
00590             {
00591                 fputs( "missing option parameter: DATA\n"
00592                        "option usage: -mod_data DATA\n"
00593                        "    where DATA is the replacement string or numbers\n",
00594                        stderr );
00595                 return -1; 
00596             }
00597 
00598             ac++;
00599             p->mod_data = argv[ac];
00600         }
00601         else if ( ! strncmp(argv[ac], "-mod_type", 6 ) )
00602         {
00603             if ( (ac+1) >= argc )
00604             {
00605                 fputs( "missing option parameter: TYPE\n"
00606                        "option usage: -mod_type TYPE\n"
00607                        "    where TYPE is 'val' or 'str'\n",
00608                        stderr );
00609                 return -1;
00610             }
00611 
00612             ac++;
00613             if ( (p->mod_type = check_mod_type(argv[ac])) == MOD_INVALID )
00614             {
00615                 fputs( "option usage: -mod_type TYPE\n", stderr );
00616                 fputs( "              where TYPE is 'str' or 'val'\n", stderr );
00617                 return -1;
00618             }
00619         }
00620         else if ( ! strncmp(argv[ac], "-offset", 4 ) )
00621         {
00622             if ( (ac+1) >= argc )
00623             {
00624                 fputs( "missing option parameter: OFFSET\n"
00625                        "option usage: -offset OFFSET\n"
00626                        "    where OFFSET is the file offset\n",
00627                        stderr );
00628                 return -1;
00629             }
00630 
00631             p->offset = atoi(argv[++ac]);
00632             if ( p->offset < 0 )
00633             {
00634                 fprintf( stderr, "bad file OFFSET <%ld>\n", p->offset );
00635                 return -1;
00636             }
00637         }
00638         else if ( ! strncmp(argv[ac], "-length", 4 ) )
00639         {
00640             if ( (ac+1) >= argc )
00641             {
00642                 fputs( "missing option parameter: LENGTH\n"
00643                        "option usage: -length LENGTH\n"
00644                        "    where LENGTH is the length to display or modify\n",
00645                        stderr );
00646                 return -1;
00647             }
00648 
00649             p->length = atoi(argv[++ac]);
00650             if ( p->length < 0 )
00651             {
00652                 fprintf( stderr, "bad LENGTH <%d>\n", p->length );
00653                 return -1;
00654             }
00655         }
00656         else if ( ! strncmp(argv[ac], "-quiet", 2 ) )
00657         {
00658             p->quiet = 1;
00659         }
00660         else if ( ! strncmp(argv[ac], "-swap_bytes", 3 ) )
00661         {
00662             p->swap = 1;
00663         }
00664         else if ( ! strncmp(argv[ac], "-ver", 2 ) )
00665         {
00666             usage( argv[0], USE_VERSION );
00667             return 1;
00668         }
00669         else if ( ! strncmp(argv[ac], "-infiles", 4 ) )
00670         {
00671             if ( (ac+1) >= argc )
00672             {
00673                 fputs( "missing input files...\n"
00674                        "option usage: -infiles file1 file2 ...\n",
00675                        stderr );
00676                 return -1;
00677             }
00678 
00679             ac++;
00680             p->num_files = argc - ac;
00681             p->flist     = argv + ac;
00682 
00683             break;      /* input files finish the argument list */
00684         }
00685         /* continue with GE info displays */
00686         else if ( ! strncmp(argv[ac], "-ge_all", 7 ) )
00687         {
00688             p->ge_disp |= GE_ALL;
00689         }
00690         else if ( ! strncmp(argv[ac], "-ge_header", 7 ) )
00691         {
00692             p->ge_disp |= GE_HEADER;
00693         }
00694         else if ( ! strncmp(argv[ac], "-ge_extras", 7 ) )
00695         {
00696             p->ge_disp |= GE_EXTRAS;
00697         }
00698         else if ( ! strncmp(argv[ac], "-ge_off", 7 ) )
00699         {
00700             p->ge_disp |= GE_OFF;
00701         }
00702         /* allow both forms - uv17 means the run number */
00703         else if ( ! strncmp(argv[ac], "-ge_uv17", 7 ) ||
00704                   ! strncmp(argv[ac], "-ge_run", 7  )    )
00705         {
00706             p->ge_disp |= GE_UV17;
00707         }
00708         /* continue with GEMS 4.x info displays */
00709         else if ( ! strncmp(argv[ac], "-ge4_all", 7 ) )
00710         {
00711             p->ge4_disp |= GE4_DISP_ALL;
00712         }
00713         else if ( ! strncmp(argv[ac], "-ge4_image", 7 ) )
00714         {
00715             p->ge4_disp |= GE4_DISP_IMAGE;
00716         }
00717         else if ( ! strncmp(argv[ac], "-ge4_series", 8 ) )
00718         {
00719             p->ge4_disp |= GE4_DISP_SERIES;
00720         }
00721         else if ( ! strncmp(argv[ac], "-ge4_study", 8 ) )
00722         {
00723             p->ge4_disp |= GE4_DISP_STUDY;
00724         }
00725         /* finish with bad option */
00726         else
00727         {
00728             fprintf( stderr, "error: unknown option, <%s>\n", argv[ac] );
00729             return -1;
00730         }
00731     }
00732 
00733     if ( p->debug > 1 )
00734         disp_param_data( p );
00735 
00736     if ( p->num_files <= 0 )
00737     {
00738         fputs( "error: missing '-infiles' option\n", stderr );
00739         return -1;
00740     }
00741 
00742     /* if only displaying GE data, no further check are necessary */
00743     if ( p->ge_disp || p->ge4_disp )
00744         return 0;
00745 
00746     /* now do all other tests for displaying/modifying generic file data */
00747 
00748     if ( p->mod_data )
00749     {
00750         p->modify = 1;           /* so we plan to modify the data */
00751         p->data_len = strlen(p->mod_data);    /* note data length */
00752     }
00753     else
00754         p->modify = 0;                             /* be explicit */
00755 
00756     if ( p->length <= 0 )
00757     {
00758         fputs( "error: missing '-length' option\n", stderr );
00759         return -1;
00760     }
00761 
00762     if ( p->modify )
00763     {
00764         if ( p->length > MAX_STR_LEN )
00765         {
00766             fprintf( stderr, "failure: length <%d> exceeds maximum %d\n",
00767                  p->length, MAX_STR_LEN );
00768             return -1;
00769         }
00770 
00771         if ( p->mod_type == MOD_CHAR )
00772         {
00773             /* we are writing one char length times */
00774             memset( g_rep_output_data, *p->mod_data, p->length );
00775             p->mod_data = g_rep_output_data;
00776             p->data_len = p->length;
00777         }
00778         else if ( p->mod_type == MOD_STR && p->length < p->data_len )
00779         {
00780             fprintf( stderr, "failure: data length <%d> exceeds length <%d>\n",
00781                      p->data_len, p->length );
00782             return -1;
00783         }
00784     }
00785 
00786     return 0;
00787 }

unsigned long THD_filesize char *    pathname
 

Return the file length (0 if file not found).

Definition at line 118 of file thd_filestuff.c.

00119 {
00120    static struct stat buf ; int ii ;
00121 
00122    if( pathname == NULL || *pathname == '\0' ) return 0 ;
00123    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00124    return buf.st_size ;
00125 }

int usage char *    prog,
int    level
 

Definition at line 2048 of file Imon.c.

02049 {
02050     if ( level == IFM_USE_SHORT )
02051     {
02052         fprintf( stderr,
02053             "usage: %s [options] -start_dir DIR\n"
02054             "usage: %s -help\n",
02055             prog, prog );
02056         return 0;
02057     }
02058     else if ( level == IFM_USE_LONG )
02059     {
02060         printf(
02061           "\n"
02062           "%s - monitor real-time acquisition of I-files\n"
02063           "\n"
02064           "    This program is intended to be run during a scanning session\n"
02065           "    on a GE scanner, to monitor the collection of I-files.  The\n"
02066           "    user will be notified of any missing slice or any slice that\n"
02067           "    is aquired out of order.\n"
02068           "\n"
02069           "    It is recommended that the user runs '%s' just after the\n"
02070           "    scanner is first prepped, and then watches for error messages\n"
02071           "    during the scanning session.  The user should terminate the\n"
02072           "    program whey they are done with all runs.\n"
02073           "\n"
02074           "    Note that '%s' can also be run separate from scanning, either\n"
02075           "    to verify the integrity of I-files, or to create a GERT_Reco2\n"
02076           "    script, which is used to create AFNI datasets.\n"
02077           "\n"
02078           "    At the present time, the user must use <ctrl-c> to terminate\n"
02079           "    the program.\n"
02080           "\n"
02081           "  ---------------------------------------------------------------\n"
02082           "  usage: %s [options] -start_dir DIR\n"
02083           "\n"
02084           "  ---------------------------------------------------------------\n"
02085           "  examples (no real-time options):\n"
02086           "\n"
02087           "    %s -start_dir 003\n"
02088           "    %s -help\n"
02089           "    %s -start_dir 003 -GERT_reco2 -quit\n"
02090           "    %s -start_dir 003 -nt 120 -start_file 043/I.901\n"
02091           "    %s -debug 2 -nice 10 -start_dir 003\n"
02092           "\n"
02093           "  examples (with real-time options):\n"
02094           "\n"
02095           "    %s -start_dir 003 -rt\n"
02096           "    %s -start_dir 003 -rt -host pickle\n"
02097           "    %s -start_dir 003 -nt 120 -rt -host pickle\n"
02098           "\n"
02099           "  ** detailed real-time example:\n"
02100           "\n"
02101           "    This example scans data starting from directory 003, expects\n"
02102           "    160 repetitions (TRs), and invokes the real-time processing,\n"
02103           "    sending data to a computer called some.remote.computer.name\n"
02104           "    (where afni is running, and which considers THIS computer to\n"
02105           "    be trusted - see the AFNI_TRUSTHOST environment variable).\n"
02106           "\n"
02107           "    Multiple DRIVE_AFNI commands are passed through '-drive_afni'\n"
02108           "    options, one requesting to open an axial image window, and\n"
02109           "    another requesting an axial graph, with 160 data points.\n"
02110           "\n"
02111           "    See README.driver for acceptable DRIVE_AFNI commands.\n"
02112           "\n"
02113           "    Also, multiple commands specific to the real-time plugin are\n"
02114           "    passed via the '-rt_cmd' options.  The 'REFIX command sets the\n"
02115           "    prefix for the datasets output by afni.  The GRAPH_XRANGE and\n"
02116           "    GRAPH_YRANGE commands set the graph dimensions for the 3D\n"
02117           "    motion correction graph (only).  And the GRAPH_EXPR command\n"
02118           "    is used to replace the 6 default motion correction graphs with\n"
02119           "    a single graph, according to the given expression, the square\n"
02120           "    root of the average squared entry of the 3 rotaion parameters,\n"
02121           "    roll, pitch and yaw, ignoring the 3 shift parameters, dx, dy\n"
02122           "    and dz.\n"
02123           "\n"
02124           "    See README.realtime for acceptable DRIVE_AFNI commands.\n"
02125           "\n"
02126           "    %s                                                   \\\n"
02127           "       -start_dir 003                                      \\\n"
02128           "       -nt 160                                             \\\n"
02129           "       -rt                                                 \\\n"
02130           "       -host some.remote.computer.name                     \\\n"
02131           "       -drive_afni 'OPEN_WINDOW axialimage'                \\\n"
02132           "       -drive_afni 'OPEN_WINDOW axialgraph pinnum=160'     \\\n"
02133           "       -rt_cmd 'PREFIX eat.more.cheese'                    \\\n"
02134           "       -rt_cmd 'GRAPH_XRANGE 160'                          \\\n"
02135           "       -rt_cmd 'GRAPH_YRANGE 1.02'                         \\\n"
02136           "       -rt_cmd 'GRAPH_EXPR sqrt((d*d+e*e+f*f)/3)'            \n"
02137           "\n"
02138           "  ---------------------------------------------------------------\n"
02139           "  notes:\n"
02140           "\n"
02141           "    - Once started, this program exits only when a fatal error\n"
02142           "      occurs (single missing or out of order slices are not\n"
02143           "      considered fatal).\n"
02144           "\n"
02145           "      ** This has been modified.  The '-quit' option tells Imon\n"
02146           "         to terminate once it runs out of new data to use.\n"
02147           "\n"
02148           "    - To terminate this program, use <ctrl-c>.\n"
02149           "\n"
02150           "  ---------------------------------------------------------------\n"
02151           "  main option:\n"
02152           "\n"
02153           "    -start_dir DIR     : (REQUIRED) specify starting directory\n"
02154           "\n"
02155           "        e.g. -start_dir 003\n"
02156           "\n"
02157           "        The starting directory, DIR, must be of the form 00n,\n"
02158           "        where n is a digit.  The program then monitors all\n"
02159           "        directories of the form ??n, created by the GE scanner.\n"
02160           "\n"
02161           "        For instance, with the option '-start_dir 003', this\n"
02162           "        program watches for new directories 003, 023, 043, etc.\n"
02163           "\n"
02164           "  ---------------------------------------------------------------\n"
02165           "  real-time options:\n"
02166           "\n"
02167           "    -rt                : specify to use the real-time facility\n"
02168           "\n"
02169           "        With this option, the user tells '%s' to use the real-time\n"
02170           "        facility, passing each volume of images to an existing\n"
02171           "        afni process on some machine (as specified by the '-host'\n"
02172           "        option).  Whenever a new volume is aquired, it will be\n"
02173           "        sent to the afni program for immediate update.\n"
02174           "\n"
02175           "        Note that afni must also be started with the '-rt' option\n"
02176           "        to make use of this.\n"
02177           "\n"
02178           "        Note also that the '-host HOSTNAME' option is not required\n"
02179           "        if afni is running on the same machine.\n"
02180           "\n"
02181           "    -drive_afni CMND   : send 'drive afni' command, CMND\n"
02182           "\n"
02183           "        e.g.  -drive_afni 'OPEN_WINDOW axialimage'\n"
02184           "\n"
02185           "        This option is used to pass a single DRIVE_AFNI command\n"
02186           "        to afni.  For example, 'OPEN_WINDOW axialimage' will open\n"
02187           "        such an axial view window on the afni controller.\n"
02188           "\n"
02189           "        Note: the command 'CMND' must be given in quotes, so that\n"
02190           "              the shell will send it as a single parameter.\n"
02191           "\n"
02192           "        Note: this option may be used multiple times.\n"
02193           "\n"
02194           "        See README.driver for more details.\n"
02195           "\n"
02196           "    -host HOSTNAME     : specify the host for afni communication\n"
02197           "\n"
02198           "        e.g.  -host mycomputer.dot.my.network\n"
02199           "        e.g.  -host 127.0.0.127\n"
02200           "        e.g.  -host mycomputer\n"
02201           "        the default host is 'localhost'\n"
02202           "\n"
02203           "        The specified HOSTNAME represents the machine that is\n"
02204           "        running afni.  Images will be sent to afni on this machine\n"
02205           "        during the execution of '%s'.\n"
02206           "\n"
02207           "        Note that the enviroment variable AFNI_TRUSTHOST must be\n"
02208           "        set on the machine running afni.  Set this equal to the\n"
02209           "        name of the machine running Imon (so that afni knows to\n"
02210           "        accept the data from the sending machine).\n"
02211           "\n"
02212           "    -rev_byte_order   : pass the reverse of the BYTEORDER to afni\n"
02213           "\n"
02214           "        Reverse the byte order that is given to afni.  In case the\n"
02215           "        detected byte order is not what is desired, this option\n"
02216           "        can be used to reverse it.\n"
02217           "\n"
02218           "        See the (obsolete) '-swap' option for more details.\n"
02219           "\n"
02220           "    -rt_cmd COMMAND   : send COMMAND(s) to realtime plugin\n"
02221           "\n"
02222           "        e.g.  -rt_cmd 'GRAPH_XRANGE 120'\n"
02223           "        e.g.  -rt_cmd 'GRAPH_XRANGE 120 \\n GRAPH_YRANGE 2.5'\n"
02224           "\n"
02225           "        This option is used to pass commands to the realtime\n"
02226           "        plugin.  For example, 'GRAPH_XRANGE 120' will set the\n"
02227           "        x-scale of the motion graph window to 120 (repetitions).\n"
02228           "\n"
02229           "        Note: the command 'COMMAND' must be given in quotes, so\n"
02230           "        that the shell will send it as a single parameter.\n"
02231           "\n"
02232           "        Note: this option may be used multiple times.\n"
02233           "\n"
02234           "        See README.realtime for more details.\n"
02235           "\n"
02236           "    -swap  (obsolete) : swap data bytes before sending to afni\n"
02237           "\n"
02238           "        Since afni may be running on a different machine, the byte\n"
02239           "        order may differ there.  This option will force the bytes\n"
02240           "        to be reversed, before sending the data to afni.\n"
02241           "\n"
02242           "        ** As of version 3.0, this option should not be necessary.\n"
02243           "           '%s' detects the byte order of the image data, and then\n"
02244           "           passes that information to afni.  The realtime plugin\n"
02245           "           will (now) decide whether to swap bytes in the viewer.\n"
02246           "\n"
02247           "           If for some reason the user wishes to reverse the order\n"
02248           "           from what is detected, '-rev_byte_order' can be used.\n"
02249           "\n"
02250           "    -zorder ORDER     : slice order over time\n"
02251           "\n"
02252           "        e.g. -zorder alt\n"
02253           "        e.g. -zorder seq\n"
02254           "        the default is 'alt'\n"
02255           "\n"
02256           "        This options allows the user to alter the slice\n"
02257           "        acquisition order in real-time mode, simliar to the slice\n"
02258           "        pattern of the '-sp' option.  The main differences are:\n"
02259           "            o  only two choices are presently available\n"
02260           "            o  the syntax is intentionally different (from that\n"
02261           "               of 'to3d' or the '-sp' option)\n"
02262           "\n"
02263           "        ORDER values:\n"
02264           "            alt   : alternating in the Z direction (over time)\n"
02265           "            seq   : sequential in the Z direction (over time)\n"
02266           "\n"
02267           "  ---------------------------------------------------------------\n"
02268           "  other options:\n"
02269           "\n"
02270           "    -debug LEVEL       : show debug information during execution\n"
02271           "\n"
02272           "        e.g.  -debug 2\n"
02273           "        the default level is 1, the domain is [0,3]\n"
02274           "        the '-quiet' option is equivalent to '-debug 0'\n"
02275           "\n"
02276           "    -help              : show this help information\n"
02277           "\n"
02278           "    -hist              : display a history of program changes\n"
02279           "\n"
02280           "    -nice INCREMENT    : adjust the nice value for the process\n"
02281           "\n"
02282           "        e.g.  -nice 10\n"
02283           "        the default is 0, and the maximum is 20\n"
02284           "        a superuser may use down to the minimum of -19\n"
02285           "\n"
02286           "        A positive INCREMENT to the nice value of a process will\n"
02287           "        lower its priority, allowing other processes more CPU\n"
02288           "        time.\n"
02289           "\n"
02290           "    -nt VOLUMES_PER_RUN : set the number of time points per run\n"
02291           "\n"
02292           "        e.g.  -nt 120\n"
02293           "\n"
02294           "        With this option, if a run stalls before the specified\n"
02295           "        VOLUMES_PER_RUN is reached (notably including the first\n"
02296           "        run), the user will be notified.\n"
02297           "\n"
02298           "        Without this option, %s will compute the expected number\n"
02299           "        of time points per run based on the first run (and will\n"
02300           "        allow the value to increase based on subsequent runs).\n"
02301           "        Therefore %s would not detect a stalled first run.\n"
02302           "\n"
02303           "    -quiet             : show only errors and final information\n"
02304           "\n"
02305           "    -quit              : quit when there is no new data\n"
02306           "\n"
02307           "        With this option, the program will terminate once a delay\n"
02308           "        in new data occurs.  This is most appropriate to use when\n"
02309           "        the image files have already been collected.\n"
02310           "\n"
02311           "    -start_file S_FILE : have %s process starting at S_FILE\n"
02312           "\n"
02313           "        e.g.  -start_file 043/I.901\n"
02314           "\n"
02315           "        With this option, any earlier I-files will be ignored\n"
02316           "        by %s.  This is a good way to start processing a later\n"
02317           "        run, if it desired not to look at the earlier data.\n"
02318           "\n"
02319           "        In this example, all files in directories 003 and 023\n"
02320           "        would be ignored, along with everything in 043 up through\n"
02321           "        I.900.  So 043/I.901 might be the first file in run 2.\n"
02322           "\n"
02323           "    -version           : show the version information\n"
02324           "\n"
02325           "  ---------------------------------------------------------------\n"
02326           "  GERT_Reco2 options:\n"
02327           "\n"
02328           "    -GERT_Reco2        : output a GERT_Reco2 script\n"
02329           "\n"
02330           "        Create a script called 'GERT_Reco2', similar to the one\n"
02331           "        that Ifile creates.  This script may be run to create the\n"
02332           "        AFNI datasets corresponding to the I-files.\n"
02333           "\n"
02334           "    -gert_outdir OUTPUT_DIR  : set output directory in GERT_Reco2\n"
02335           "\n"
02336           "        e.g. -gert_outdir subject_A7\n"
02337           "        e.g. -od subject_A7\n"
02338           "        the default is '-gert_outdir afni'\n"
02339           "\n"
02340           "        This will add '-od OUTPUT_DIR' to the @RenamePanga command\n"
02341           "        in the GERT_Reco2 script, creating new datasets in the\n"
02342           "        OUTPUT_DIR directory, instead of the 'afni' directory.\n"
02343           "\n"
02344           "    -sp SLICE_PATTERN  : set output slice pattern in GERT_Reco2\n"
02345           "\n"
02346           "        e.g. -sp alt-z\n"
02347           "        the default is 'alt+z'\n"
02348           "\n"
02349           "        This options allows the user to alter the slice\n"
02350           "        acquisition pattern in the GERT_Reco2 script.\n"
02351           "\n"
02352           "        See 'to3d -help' for more information.\n"
02353           "\n"
02354           "  ---------------------------------------------------------------\n"
02355           "\n"
02356           "  Author: R. Reynolds - %s\n"
02357           "\n"
02358           "                        (many thanks to R. Birn)\n"
02359           "\n",
02360           prog, prog, prog, prog,
02361           prog, prog, prog, prog, prog, prog, prog, prog, prog,
02362           prog, prog, prog, prog, prog, prog, prog,
02363           IFM_VERSION
02364         );
02365 
02366         return 0;
02367     }
02368     else if ( level == IFM_USE_HIST )
02369     {
02370         fputs( g_history, stdout );
02371         return 0;
02372     }
02373     else if ( level == IFM_USE_VERSION )
02374     {
02375         printf( "%s: %s, compile date: %s\n",
02376                 prog, IFM_VERSION, __DATE__ );
02377         return 0;
02378     }
02379 
02380     fprintf( stderr, "error: usage() called with illegal level <%d>\n", level );
02381 
02382     return -1;
02383 }

int write_data_to_file FILE *    fp,
char *    filename,
param_t   p
 

Definition at line 384 of file file_tool.c.

References c, param_t::data_len, param_t::debug, g_rep_output_data, param_t::length, MOD_CHAR, param_t::mod_data, MOD_F4, MOD_F8, MOD_S1, MOD_S2, MOD_S4, MOD_STR, param_t::mod_type, MOD_U1, MOD_U2, MOD_U4, mtype_size(), p, strtod(), param_t::swap, swap_2(), and swap_4().

Referenced by process_file().

00385 {
00386     double   dval;
00387     char   * outp, * inp, * endp;
00388     int      dsize, c, nbytes;
00389 
00390     if ( (dsize = mtype_size( p->mod_type )) < 1 )
00391     {
00392         fprintf(stderr,"** bad size %d for mod_type %d\n", dsize, p->mod_type);
00393         return -1;
00394     }
00395 
00396     if ( p->debug > 1 )
00397         fprintf(stderr,"-- dsize = %d\n", dsize);
00398 
00399     /* deal with characters separately */
00400     if ( p->mod_type == MOD_STR || p->mod_type == MOD_CHAR )
00401     {
00402         int remaining = p->length - p->data_len; /* note remainder (if any) */
00403 
00404         if ( (nbytes=fwrite(p->mod_data, 1, p->data_len, fp)) != p->data_len )
00405         {
00406             fprintf( stderr, "\nfailure: wrote only %d of %d bytes to '%s'\n",
00407                      nbytes, p->data_len, filename );
00408             fclose( fp );
00409             return -1;
00410         }
00411 
00412         /* and fill with 0 */
00413         for ( c = 0; c < remaining; c++ )
00414             fputc( '\0', fp );
00415 
00416         return p->length;
00417     }
00418 
00419     if ( p->debug > 1 ) fprintf(stderr,"++ values: ");
00420 
00421     /* now write numerical values into g_rep_output_data */
00422     outp = g_rep_output_data;
00423     inp  = p->mod_data;
00424     memset(outp, 0, p->length);
00425     for ( c = 0; (c+dsize) <= p->length; c += dsize, outp += dsize )
00426     {
00427         dval = strtod( inp, &endp );
00428 
00429         if ( endp && inp != endp )   /* then we read something in */
00430         {
00431             switch (p->mod_type)
00432             {
00433                 default:
00434                     fprintf(stderr,"** wdtf: bad type %d\n", p->mod_type);
00435                     return -1;
00436                 case MOD_U1:
00437                     *(unsigned char *)outp = (unsigned char)dval;
00438                     break;
00439                 case MOD_S1:
00440                     *(char *)outp = (char)dval;
00441                     break;
00442                 case MOD_U2:
00443                     *(unsigned short *)outp = (unsigned short)dval;
00444                     break;
00445                 case MOD_S2:
00446                     *(short *)outp = (short)dval;
00447                     break;
00448                 case MOD_U4:
00449                     *(unsigned long *)outp = (unsigned long)dval;
00450                     break;
00451                 case MOD_S4:
00452                     *(long *)outp = (long)dval;
00453                     break;
00454                 case MOD_F4:
00455                     *(float *)outp = (float)dval;
00456                     break;
00457                 case MOD_F8:
00458                     *(double *)outp = dval;
00459                     break;
00460             }
00461 
00462             if ( p->swap )
00463             {
00464                 if ( dsize == 2 )
00465                     swap_2( (void *)outp );
00466                 else if ( dsize == 4 )
00467                     swap_4( (void *)outp );
00468             }
00469 
00470             if ( p->debug > 1 ) fprintf(stderr," %f", dval);
00471         }
00472         else
00473             break;      /* done */
00474 
00475         inp = endp;     /* prepare to go after a new number */
00476     }
00477 
00478     if ( p->debug > 1 ) fputc('\n', stderr);
00479 
00480     /* now just write the data out */
00481     nbytes = fwrite(g_rep_output_data, 1, p->length, fp);
00482     if ( nbytes != p->length )
00483     {
00484         fprintf(stderr,"** wrote only %d of %d bytes of binary data\n",
00485                 nbytes, p->length);
00486         return nbytes;
00487     }
00488 
00489     return p->length;
00490 }
 

Powered by Plone

This site conforms to the following standards: