#ifndef NIFTI2_TOOL_H #define NIFTI2_TOOL_H #define NT_CMD_LEN 2048 typedef struct{ int len; const char ** list; } str_list; typedef struct{ int len; int * list; } int_list; typedef struct{ /* action options (flags) */ int check_hdr, check_nim; int diff_hdr, diff_hdr1, diff_hdr2, diff_nim; int disp_hdr1, disp_hdr2, disp_hdr, disp_nim, disp_ana; int disp_exts, add_exts, rm_exts, disp_cext; int run_misc_tests; int mod_hdr, mod_hdr2, mod_nim; int swap_hdr, swap_ana, swap_old; int strip; /* strip extras from dataset(s) */ int cbl, cci; /* -copy_XXX option flags */ int copy_image; /* straight read (no cci) */ int dts, dci, dci_lines; /* display collapsed img flags */ int make_im; /* create a new image on the fly */ int64_t ci_dims[8]; /* user dims list (last 7 valid) */ int64_t new_dim[8]; /* user dim list for new image */ int new_datatype; /* datatype for new image */ int convert2dtype; /* convert data to new type */ int cnvt_verify; /* do we verify the conversion */ int cnvt_fail_choice; /* what if conversion fails */ int debug, keep_hist; /* debug level and history flag */ int overwrite; /* overwrite flag */ char * prefix; /* for output file */ str_list elist; /* extension strings */ int_list etypes; /* extension type list */ str_list flist; /* fields (to display or modify) */ str_list vlist; /* values (to set fields to) */ str_list infiles; /* input files */ char command[NT_CMD_LEN]; /* for inserting the command */ } nt_opts; #define USE_SHORT 1 #define USE_FULL 2 #define USE_HIST 3 #define USE_FIELD_HDR1 11 #define USE_FIELD_HDR2 12 #define USE_FIELD_NIM1 21 #define USE_FIELD_NIM2 22 #define USE_FIELD_ANA 31 #define USE_DTYPES 41 #define USE_VERSION 51 #define USE_VER_MAN 52 /* for unix man-page formatting */ #define USE_SEE_ALSO 53 /* for unix man-page formatting */ #define CHECK_NEXT_OPT(n,m,str) \ do { if ( (n) >= (m) ) { \ fprintf(stderr,"** option '%s': missing parameter\n",str); \ fprintf(stderr," consider: 'nifti_tool -help'\n"); \ return 1; } \ } while(0) #define CHECK_NEXT_OPT_MSG(n,m,str,msg) \ do { if ( (n) >= (m) ) { \ fprintf(stderr,"** option '%s': %s\n",str,msg); \ fprintf(stderr," consider: 'nifti_tool -help'\n"); \ return 1; } \ } while(0) /*---------------------------------------------------------------------- * this structure and definitions will be used to process the nifti_1_header * and nifti_image structure fields (actions disp, diff, mod) *----------------------------------------------------------------------*/ #define NT_FIELD_NAME_LEN 20 /* more than length of longest name */ #define NT_HDR1_NUM_FIELDS 43 /* in the nifti_1_header struct */ #define NT_HDR2_NUM_FIELDS 37 /* in the nifti_2_header struct */ #define NT_ANA_NUM_FIELDS 47 /* in the nifti_analyze75 struct */ #define NT_NIM_NUM_FIELDS 63 /* in the nifti_image struct */ #define NT_HDR_TIME_NFIELDS 8 /* num slice timing fields in hdr */ #define NT_NIM_TIME_NFIELDS 11 /* num slice timing fields in nim */ #define NT_DT_STRING -0xfff /* some strange number to abuse... */ #define NT_DT_POINTER -0xfef /* some strange number to abuse... */ #define NT_DT_CHAR_PTR -0xfee /* another... */ #define NT_DT_EXT_PTR -0xfed /* and another... */ typedef struct { int type; /* one of the DT_* types from nifti1.h */ int offset; /* bytes from the start of the struct */ int size; /* size of one element type */ int len; /* number of elements */ char name[NT_FIELD_NAME_LEN]; /* actual structure name used */ } field_s; /* for computing the offset from the start of the struct */ #define NT_OFF(str,field) ((int)( ((char *)&str.field) - ((char *)&str) )) #define SHOW_STRUCT_OFFSET(str,field,mesg) do { str ss; \ if(mesg)printf("%s ",(char*)mesg); \ printf("%s.%s @ offset %d\n", #str, #field, NT_OFF(ss,field)); } \ while (0) /* call fill_field() for a single type, name and number of elements */ /* nstr is the base struct, and fldp is a field pointer */ #define NT_SFILL(nstr,fldp,type,name,num,rv) do{ \ rv=fill_field(fldp,type,NT_OFF(nstr,name),num,#name); \ fldp++; } while (0) #define NT_MAKE_IM_NAME "MAKE_IM" /* ================================================================= */ /* data conversionn operations */ /* -------------------------------------------- */ /* copy from src to dest, chaning type enroute */ /* dtype, dptr : destination type and pointer */ /* stype, sptr : source type and pointer */ /* nvals : number of values to copy */ #define NT_DCONVERT_NO_CHECKS(dptr, dtype, sptr, stype, nvals) \ do { \ dtype * pd = dptr; \ stype * ps = sptr; \ int64_t index; \ for(index=0; index