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  

3ddata.h File Reference

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <X11/Intrinsic.h>
#include "mcw_malloc.h"
#include "killer.h"
#include "vecmat.h"
#include "machdep.h"
#include "mrilib.h"
#include "tagset.h"
#include "thd_compress.h"
#include "niml.h"
#include "afni_suma.h"
#include <stdarg.h>

Go to the source code of this file.


Data Structures

union  ATR_any
struct  ATR_float
struct  ATR_int
struct  ATR_string
struct  FD_brick
struct  MCW_function_list
struct  MCW_idcode
struct  MRI_3dalign_basis
struct  MRI_warp3D_align_basis
struct  MRI_warp3D_param_def
struct  THD_3dim_dataset
struct  THD_3dim_dataset_array
struct  THD_affine_warp
struct  THD_brick_stats
struct  THD_coorder
struct  THD_datablock
struct  THD_datablock_array
struct  THD_dataxes
struct  THD_diskptr
struct  THD_linear_mapping
struct  THD_marker_set
struct  THD_session
struct  THD_sessionlist
struct  THD_slist_find
struct  THD_statistics
struct  THD_string_array
struct  THD_talairach_12_warp
struct  THD_timeaxis
union  THD_warp
struct  Tmask
struct  XtPointer_array

Defines

#define DSET_VERSION_LATEST   "1996-07-10"
#define DSET_VERSION_COMPARE(v1, v2)   strcmp(v1,v2)
#define ALLOW_MINC
#define STRING_HAS_SUFFIX(ss, suf)
#define THD_MAX_NAME   256
#define THD_MAX_LABEL   38
#define THD_MAX_PREFIX   (127+1)
#define THD_MAX_VIEWCODE   (4+1)
#define THD_MAX_SUFFIX   (4+1)
#define THD_MAX_FILECODE   (THD_MAX_PREFIX+THD_MAX_VIEWCODE)
#define THD_DEFAULT_LABEL   "Viggo!"
#define THD_MAX_SESSION_SIZE   4096
#define THD_MAX_NUM_SESSION   80
#define THD_MAX_CHOICES   THD_MAX_SESSION_SIZE
#define THD_MAX_MARKSET   5
#define FAIL   -1
#define SUCCESS   1
#define ILLEGAL_TYPE   -666
#define RETURNS_STRING   1
#define NEEDS_DSET_INDEX   2
#define PROCESS_MRI_IMAGE   4
#define FUNC_0D   0
#define FUNC_1D   1
#define FUNC_2D   2
#define FUNC_3D   3
#define FUNC_FIM   71
#define TWO_ONE(x, y)   x ## y
#define TWO_TWO(x, y)   TWO_ONE(x,y)
#define COPY_INTO_STRUCT(str, off, type, ptr, n)   (void) memcpy( (char *)(&(str))+(off), (char *)(ptr), (n)*sizeof(type) )
#define COPY_FROM_STRUCT(str, off, type, ptr, n)   (void) memcpy( (char *)(ptr), (char *)(&(str))+(off), (n)*sizeof(type) )
#define MCW_strncpy(dest, src, n)   ( (void) strncpy( (dest) , (src) , (n)-1 ) , (dest)[(n)-1] = '\0' )
#define IC_DSET   44301
#define IC_FLIM   55402
#define INC_XTARR   8
#define INIT_XTARR(name)
#define ADDTO_XTARR(name, bblk)
#define XTARR_NUM(name)   ((name)->num)
#define XTARR_XT(name, i)   ((name)->ar[i])
#define XTARR_IC(name, i)   ((name)->ic[i])
#define FREE_XTARR(name)
#define DESTROY_XTARR   FREE_XTARR
#define SARR_STRING(ss, qq)   ((ss)->ar[(qq)])
#define SARR_NUM(ss)   ((ss)->num)
#define INC_SARR   64
#define INIT_SARR(name)
#define ADDTO_SARR(name, str)
#define REMOVEFROM_SARR(name, ijk)
#define DESTROY_SARR(name)
#define PATH_CONCAT(pout, p1, p2)
#define ATR_STRING_TYPE   0
#define ATR_FLOAT_TYPE   1
#define ATR_INT_TYPE   2
#define FIRST_ATR_TYPE   0
#define LAST_ATR_TYPE   2
#define ZBLOCK   126
#define MAPPING_LINEAR_TYPE   0
#define MAPPING_LINEAR_STR   "LINEAR_MAPPING"
#define FIRST_MAPPING_TYPE   0
#define LAST_MAPPING_TYPE   0
#define COPY_LMAP_BOUNDS(m1, m2)   ( (m1).bot=(m2).bot , (m1).top=(m2).top )
#define LOAD_INVERSE_LMAP(map)
#define MAPPING_LINEAR_FSTART   XtOffsetOf(THD_linear_mapping,mfor)
#define MAPPING_LINEAR_FEND   (XtOffsetOf(THD_linear_mapping,top)+sizeof(THD_fvec3))
#define MAPPING_LINEAR_FSIZE   ((MAPPING_LINEAR_FEND-MAPPING_LINEAR_FSTART)/sizeof(float))
#define DUMP_LMAP(m)
#define MARKS_MAXNUM   10
#define MARKS_MAXLAB   20
#define MARKS_MAXHELP   256
#define MARKS_MAXFLAG   8
#define MARKS_FSIZE   (MARKS_MAXNUM*3)
#define MARKS_FSTART   XtOffsetOf(THD_marker_set,xyz)
#define MARKS_LSIZE   (MARKS_MAXNUM*MARKS_MAXLAB)
#define MARKS_LSTART   XtOffsetOf(THD_marker_set,label)
#define MARKS_HSIZE   (MARKS_MAXNUM*MARKS_MAXHELP)
#define MARKS_HSTART   XtOffsetOf(THD_marker_set,help)
#define MARKS_ASIZE   MARKS_MAXFLAG
#define MARKS_ASTART   XtOffsetOf(THD_marker_set,aflags)
#define MARKSET_ALIGN   1
#define MARKSET_BOUNDING   2
#define MARKACTION_NONE   0
#define MARKACTION_WARP   1
#define MARKACTION_REGISTER   2
#define NMARK_ALIGN   5
#define IMARK_ACSE   0
#define IMARK_ACPM   1
#define IMARK_PCIE   2
#define IMARK_MSA1   3
#define IMARK_MSA2   4
#define NMARK_BOUNDING   6
#define IMARK_MANT   0
#define IMARK_MPOS   1
#define IMARK_MSUP   2
#define IMARK_MINF   3
#define IMARK_MLEF   4
#define IMARK_MRIG   5
#define ATLAS_FRONT_TO_AC   70.0
#define ATLAS_AC_TO_PC   23.0
#define ATLAS_PC_TO_BACK   79.0
#define ATLAS_BOT_TO_AC   42.0
#define ATLAS_AC_TO_TOP   74.0
#define ATLAS_AC_TO_LAT   68.0
#define ATLAS_BBOX_LAT   80.0
#define ATLAS_BBOX_ANT   80.0
#define ATLAS_BBOX_POS   110.0
#define ATLAS_BBOX_INF   55.0
#define ATLAS_BBOX_SUP   85.0
#define ATLAS_BBOX_INF_NEW   65.0
#define ATLAS_ALIGNBOX_LAT   95.0
#define ATLAS_ALIGNBOX_ANT   95.0
#define ATLAS_ALIGNBOX_POS   140.0
#define ATLAS_ALIGNBOX_SUP   100.0
#define ATLAS_ALIGNBOX_INF   70.0
#define MAX_ALLOWED_DEVIATION   2.0
#define MIN_ALLOWED_DEVIATION   0.5
#define WARP_AFFINE_TYPE   0
#define WARP_AFFINE_STR   "WARP_AFFINE"
#define WARP_TALAIRACH_12_TYPE   1
#define WARP_TALAIRACH_12_STR   "WARP_TALAIRACH_12"
#define FIRST_WARP_TYPE   0
#define LAST_WARP_TYPE   1
#define RESAM_NN_TYPE   0
#define RESAM_NN_STR   "Nearest Neighbor"
#define RESAM_LINEAR_TYPE   1
#define RESAM_LINEAR_STR   "Linear Interpolation"
#define RESAM_CUBIC_TYPE   2
#define RESAM_CUBIC_STR   "Cubic Interpolation"
#define RESAM_BLOCK_TYPE   3
#define RESAM_BLOCK_STR   "Blocky Interpolation"
#define FIRST_RESAM_TYPE   0
#define LAST_RESAM_TYPE   3
#define NSTR_SHORT_RESAM   2
#define W_RAS   0
#define W_LAS   1
#define W_RMS   2
#define W_LMS   3
#define W_RPS   4
#define W_LPS   5
#define W_RAI   6
#define W_LAI   7
#define W_RMI   8
#define W_LMI   9
#define W_RPI   10
#define W_LPI   11
#define WARP_TALAIRACH_12_SIZE   (12*MAPPING_LINEAR_FSIZE)
#define DUMP_T12_MAP(t12, xx, yy, zz)
#define DUMP_T12_WARP(t12)
#define WARP_AFFINE_SIZE   (MAPPING_LINEAR_FSIZE)
#define ISVALID_WARP(ww)
#define IDENTITY_WARP
#define ROTGEN_WARP(th, ff, aa, bb)
#define ROTX_WARP(th)   ROTGEN_WARP(th,0,1,2)
#define ROTY_WARP(th)   ROTGEN_WARP(th,1,2,0)
#define ROTZ_WARP(th)   ROTGEN_WARP(th,2,0,1)
#define CEN_WARP(ww, xin, yin, zin, xout, yout, zout)
#define DISKPTR_TYPE   47
#define THD_MAX_RANK   3
#define THD_MIN_RANK   3
#define THD_MAX_RANK_EVER   5
#define DATASET_HEADER_SUFFIX   "HEAD"
#define DATASET_BRICK_SUFFIX   "BRIK"
#define DATASET_NOTES_SUFFIX   "NOTE"
#define STORAGE_UNDEFINED   0
#define STORAGE_BY_BRICK   2
#define STORAGE_BY_MINC   3
#define STORAGE_BY_VOLUMES   4
#define STORAGE_BY_ANALYZE   5
#define STORAGE_BY_CTFMRI   6
#define STORAGE_BY_CTFSAM   7
#define STORAGE_BY_1D   8
#define STORAGE_BY_3D   9
#define STORAGE_BY_NIFTI   10
#define STORAGE_BY_MPEG   11
#define LAST_STORAGE_MODE   11
#define ATRNAME_BYTEORDER   "BYTEORDER_STRING"
#define ISVALID_DISKPTR(dk)   ( (dk)!=NULL && (dk)->type==DISKPTR_TYPE )
#define PREFIX_VIEW_TO_FILECODE(pr, vv, fc)   sprintf( (fc),"%s+%s",(pr),(vv) )
#define FILECODE_TO_PREFIX(fc, pr)
#define FILENAME_TO_PREFIX(fn, pr)
#define DATABLOCK_TYPE   37
#define DATABLOCK_MEM_UNDEFINED   1
#define DATABLOCK_MEM_MALLOC   2
#define DATABLOCK_MEM_MMAP   4
#define DATABLOCK_MEM_ANY   (DATABLOCK_MEM_MALLOC | DATABLOCK_MEM_MMAP)
#define DATABLOCK_MEM_SHARED   8
#define ISVALID_MEM_CODE(mm)
#define MMAP_THRESHOLD   999999
#define DBLK_mallocize(db)   THD_force_malloc_type((db),DATABLOCK_MEM_MALLOC)
#define DBLK_mmapize(db)   THD_force_malloc_type((db),DATABLOCK_MEM_MMAP)
#define DBLK_anyize(db)   THD_force_malloc_type((db),DATABLOCK_MEM_ANY)
#define DBLK_IS_MALLOC(db)   ((db)->malloc_type == DATABLOCK_MEM_MALLOC)
#define DBLK_IS_MMAP(db)   ((db)->malloc_type == DATABLOCK_MEM_MMAP)
#define DBLK_IS_SHARED(db)   ((db)->malloc_type == DATABLOCK_MEM_SHARED)
#define DBLK_shareize(db)   THD_force_malloc_type((db),DATABLOCK_MEM_SHARED)
#define DBLK_lock(db)   ((db)->locked = 1)
#define DBLK_unlock(db)   ((db)->locked = ((db)->locked<2) ? 0 : 2)
#define DBLK_LOCKED(db)   ((db)->locked)
#define DBLK_superlock(db)   ((db)->locked = 2)
#define DBLK_IS_MASTERED(db)   ((db)->master_nvals > 0 && (db)->master_ival != NULL && (db)->master_bytes != NULL)
#define THD_null_datablock_auxdata(blk)
#define ISVALID_DATABLOCK(bk)   ( (bk) != NULL && (bk)->type == DATABLOCK_TYPE )
#define ISVALID_DBLK   ISVALID_DATABLOCK
#define INC_DBARR   8
#define INIT_DBARR(name)
#define ADDTO_DBARR(name, bblk)
#define FREE_DBARR(name)
#define DATAXES_TYPE   27
#define DEFAULT_RESAMPLE_VOX   1.0
#define ORI_R2L_TYPE   0
#define ORI_R2L_STR   "Right-to-Left"
#define ORI_L2R_TYPE   1
#define ORI_L2R_STR   "Left-to-Right"
#define ORI_P2A_TYPE   2
#define ORI_P2A_STR   "Posterior-to-Anterior"
#define ORI_A2P_TYPE   3
#define ORI_A2P_STR   "Anterior-to-Posterior"
#define ORI_I2S_TYPE   4
#define ORI_I2S_STR   "Inferior-to-Superior"
#define ORI_S2I_TYPE   5
#define ORI_S2I_STR   "Superior-to-Inferior"
#define ORI_GEN_TYPE   6
#define ORI_GEN_STR   "General"
#define FIRST_ORIENT_TYPE   0
#define LAST_ORIENT_TYPE   5
#define LONGEST_ORIENT_TYPESTR   strlen(ORI_P2A_STR)
#define ORIENT_OPPOSITE(orc)   ( ((orc) % 2 == 0) ? ((orc)+1) : ((orc)-1) )
#define DAXES_XCEN(dax)   ((dax)->xxorg + 0.5*((dax)->nxx - 1) * (dax)->xxdel)
#define DAXES_YCEN(dax)   ((dax)->yyorg + 0.5*((dax)->nyy - 1) * (dax)->yydel)
#define DAXES_ZCEN(dax)   ((dax)->zzorg + 0.5*((dax)->nzz - 1) * (dax)->zzdel)
#define DAXES_NUM(dax, ori)
#define DATAXES_TO_DISKPTR(ds)
#define ISVALID_DATAXES(dax)   ( (dax) != NULL && (dax)->type == DATAXES_TYPE )
#define EQUIV_DATAXES(cax, dax)
#define TIMEAXIS_TYPE   907
#define UNITS_MSEC_TYPE   77001
#define UNITS_SEC_TYPE   77002
#define UNITS_HZ_TYPE   77003
#define UNITS_TYPE_LABEL(uu)   UNITS_TYPE_labelstring[(uu)-UNITS_MSEC_TYPE]
#define ISVALID_TIMEAXIS(tax)   ((tax) != NULL && (tax)->type == TIMEAXIS_TYPE)
#define STATISTICS_TYPE   17
#define ISVALID_STATISTIC(st)   ( (st) != NULL && (st)->type == STATISTICS_TYPE )
#define ISVALID_BSTAT(bst)   ( (bst).min <= (bst).max )
#define INVALIDATE_BSTAT(bst)   ( (bst).min = 1.0 , (bst).max = -1.0 )
#define KILL_STATISTIC(st)
#define MCW_IDPREFIX   "NIH_"
#define MCW_IDSIZE   32
#define MCW_IDDATE   48
#define EQUIV_IDCODES(id, ie)   (strncmp((id).str,(ie).str,MCW_IDSIZE) == 0)
#define EQUIV_DSETS(ds, es)
#define DUPLICATE_DSETS(ds, es)
#define ZERO_IDCODE(id)   ((id).str[0] = (id).date[0] = '\0')
#define ISZERO_IDCODE(id)   ((id).str[0] == '\0')
#define ATRNAME_IDSTRING   "IDCODE_STRING"
#define ATRNAME_IDDATE   "IDCODE_DATE"
#define ATRNAME_IDANATPAR   "IDCODE_ANAT_PARENT"
#define ATRNAME_IDWARPPAR   "IDCODE_WARP_PARENT"
#define HEAD_ANAT_TYPE   0
#define HEAD_ANAT_STR   "3DIM_HEAD_ANAT"
#define HEAD_FUNC_TYPE   1
#define HEAD_FUNC_STR   "3DIM_HEAD_FUNC"
#define GEN_ANAT_TYPE   2
#define GEN_ANAT_STR   "3DIM_GEN_ANAT"
#define GEN_FUNC_TYPE   3
#define GEN_FUNC_STR   "3DIM_GEN_FUNC"
#define FIRST_3DIM_TYPE   0
#define LAST_3DIM_TYPE   3
#define LONGEST_3DIM_TYPESTR   strlen(HEAD_ANAT_STR)
#define VIEW_ORIGINAL_TYPE   0
#define VIEW_ORIGINAL_STR   "Original View"
#define VIEW_ORIGINAL_CODE   "orig"
#define VIEW_ACPCALIGNED_TYPE   1
#define VIEW_ACPCALIGNED_STR   "AC-PC Aligned"
#define VIEW_ACPCALIGNED_CODE   "acpc"
#define VIEW_TALAIRACH_TYPE   2
#define VIEW_TALAIRACH_STR   "Talairach View"
#define VIEW_TALAIRACH_CODE   "tlrc"
#define VIEW_REGISTERED_TYPE   3
#define VIEW_REGISTERED_STR   "Registered View"
#define VIEW_REGISTERED_CODE   "rgst"
#define FIRST_VIEW_TYPE   0
#define LAST_VIEW_TYPE   2
#define LONGEST_VIEW_TYPESTR   strlen(VIEW_REGISTERED_STR)
#define FUNC_FIM_TYPE   0
#define FUNC_FIM_STR   "Intensity"
#define FUNC_FIM_PREFIX   "fim"
#define FUNC_FIM_LABEL   "fim"
#define FUNC_FIM_DESCRIPTOR   "Functional Intensity"
#define FUNC_FIM_MASK   (1 << FUNC_FIM_TYPE)
#define FUNC_PAIR_TYPE   1
#define FUNC_PAIR_STR   "Inten+Thr"
#define FUNC_PAIR_PREFIX   "fith"
#define FUNC_THR_TYPE   FUNC_PAIR_TYPE
#define FUNC_THR_STR   FUNC_PAIR_STR
#define FUNC_THR_PREFIX   FUNC_PAIR_PREFIX
#define FUNC_THR_TOP   1.0
#define FUNC_THR_SCALE_SHORT   10000
#define FUNC_THR_SCALE_BYTE   100
#define FUNC_THR_LABEL   "Thr "
#define FUNC_THR_DESCRIPTOR   "Old style threshold"
#define FUNC_THR_MASK   (1 << FUNC_PAIR_TYPE)
#define FUNC_COR_TYPE   2
#define FUNC_COR_STR   "Inten+Cor"
#define FUNC_COR_PREFIX   "fico"
#define FUNC_COR_TOP   1.0
#define FUNC_COR_SCALE_SHORT   10000
#define FUNC_COR_SCALE_BYTE   100
#define FUNC_COR_LABEL   "Corr"
#define FUNC_COR_DESCRIPTOR   "Correlation Coefficient"
#define FUNC_COR_MASK   (1 << FUNC_COR_TYPE)
#define FUNC_TT_TYPE   3
#define FUNC_TT_STR   "Inten+Ttest"
#define FUNC_TT_PREFIX   "fitt"
#define FUNC_TT_TOP   10.0
#define FUNC_TT_SCALE_SHORT   1000
#define FUNC_TT_SCALE_BYTE   10
#define FUNC_TT_LABEL   "T-t "
#define FUNC_TT_DESCRIPTOR   "Student t-statistic"
#define FUNC_TT_MASK   (1 << FUNC_TT_TYPE)
#define FUNC_FT_TYPE   4
#define FUNC_FT_STR   "Inten+Ftest"
#define FUNC_FT_PREFIX   "fift"
#define FUNC_FT_TOP   100.0
#define FUNC_FT_SCALE_SHORT   100
#define FUNC_FT_SCALE_BYTE   1
#define FUNC_FT_LABEL   "F-t "
#define FUNC_FT_DESCRIPTOR   "Fisher F-statistic"
#define FUNC_FT_MASK   (1 << FUNC_FT_TYPE)
#define FUNC_ZT_TYPE   5
#define FUNC_ZT_STR   "Inten+Ztest"
#define FUNC_ZT_PREFIX   "fizt"
#define FUNC_ZT_TOP   10.0
#define FUNC_ZT_SCALE_SHORT   1000
#define FUNC_ZT_SCALE_BYTE   10
#define FUNC_ZT_LABEL   "Z-t "
#define FUNC_ZT_DESCRIPTOR   "Normal (Gaussian) Z"
#define FUNC_ZT_MASK   (1 << FUNC_ZT_TYPE)
#define FUNC_CT_TYPE   6
#define FUNC_CT_STR   "Inten+ChiSq"
#define FUNC_CT_PREFIX   "fict"
#define FUNC_CT_TOP   100.0
#define FUNC_CT_SCALE_SHORT   100
#define FUNC_CT_SCALE_BYTE   1
#define FUNC_CT_LABEL   "ChiS"
#define FUNC_CT_DESCRIPTOR   "Chi-Squared statistic"
#define FUNC_CT_MASK   (1 << FUNC_CT_TYPE)
#define FUNC_BT_TYPE   7
#define FUNC_BT_STR   "Inten+Beta"
#define FUNC_BT_PREFIX   "fibt"
#define FUNC_BT_TOP   1.0
#define FUNC_BT_SCALE_SHORT   10000
#define FUNC_BT_SCALE_BYTE   100
#define FUNC_BT_LABEL   "Beta"
#define FUNC_BT_DESCRIPTOR   "Beta Distribution"
#define FUNC_BT_MASK   (1 << FUNC_BT_TYPE)
#define FUNC_BN_TYPE   8
#define FUNC_BN_STR   "Inten+Binom"
#define FUNC_BN_PREFIX   "fibn"
#define FUNC_BN_TOP   100.0
#define FUNC_BN_SCALE_SHORT   100
#define FUNC_BN_SCALE_BYTE   1
#define FUNC_BN_LABEL   "Bino"
#define FUNC_BN_DESCRIPTOR   "Binomial Distribution"
#define FUNC_BN_MASK   (1 << FUNC_BN_TYPE)
#define FUNC_GT_TYPE   9
#define FUNC_GT_STR   "Inten+Gamma"
#define FUNC_GT_PREFIX   "figt"
#define FUNC_GT_TOP   10.0
#define FUNC_GT_SCALE_SHORT   1000
#define FUNC_GT_SCALE_BYTE   10
#define FUNC_GT_LABEL   "Gam "
#define FUNC_GT_DESCRIPTOR   "Gamma Distribution"
#define FUNC_GT_MASK   (1 << FUNC_GT_TYPE)
#define FUNC_PT_TYPE   10
#define FUNC_PT_STR   "Inten+Poisson"
#define FUNC_PT_PREFIX   "fipt"
#define FUNC_PT_TOP   100.0
#define FUNC_PT_SCALE_SHORT   100
#define FUNC_PT_SCALE_BYTE   1
#define FUNC_PT_LABEL   "Pois"
#define FUNC_PT_DESCRIPTOR   "Poisson Distribution"
#define FUNC_PT_MASK   (1 << FUNC_PT_TYPE)
#define FUNC_BUCK_TYPE   11
#define FUNC_BUCK_STR   "Func-Bucket"
#define FUNC_BUCK_PREFIX   "fbuc"
#define FUNC_BUCK_TOP   1.0
#define FUNC_BUCK_SCALE_SHORT   1
#define FUNC_BUCK_SCALE_BYTE   1
#define FUNC_BUCK_LABEL   "Buck"
#define FUNC_BUCK_DESCRIPTOR   "Function Bucket"
#define FUNC_BUCK_MASK   (1 << FUNC_BUCK_TYPE)
#define FIRST_FUNC_TYPE   0
#define LAST_FUNC_TYPE   11
#define FIRST_STAT_TYPE   2
#define LAST_STAT_TYPE   10
#define FUNC_ALL_MASK
#define LONGEST_FUNC_TYPESTR   strlen(FUNC_PT_STR)
#define AFNI_FIRST_STATCODE   FUNC_COR_TYPE
#define AFNI_LAST_STATCODE   FUNC_PT_TYPE
#define FIMTHR   0
#define FUNC_HAVE_FIM(ftyp)
#define FUNC_HAVE_THR(ftyp)
#define FUNC_IS_STAT(ftyp)   ((ftyp) >= FIRST_STAT_TYPE && (ftyp) <= LAST_STAT_TYPE)
#define FUNC_HAVE_PVAL   FUNC_IS_STAT
#define MAX_STAT_AUX   64
#define ANAT_SPGR_TYPE   0
#define ANAT_SPGR_STR   "Spoiled GRASS"
#define ANAT_SPGR_PREFIX   "spgr"
#define ANAT_SPGR_MASK   (1 << ANAT_SPGR_TYPE)
#define ANAT_FSE_TYPE   1
#define ANAT_FSE_STR   "Fast Spin Echo"
#define ANAT_FSE_PREFIX   "fse"
#define ANAT_FSE_MASK   (1 << ANAT_FSE_TYPE)
#define ANAT_EPI_TYPE   2
#define ANAT_EPI_STR   "Echo Planar"
#define ANAT_EPI_PREFIX   "epan"
#define ANAT_EPI_MASK   (1 << ANAT_EPI_TYPE)
#define ANAT_MRAN_TYPE   3
#define ANAT_MRAN_STR   "MRI Anatomy"
#define ANAT_MRAN_PREFIX   "anat"
#define ANAT_MRAN_MASK   (1 << ANAT_MRAN_TYPE)
#define ANAT_CT_TYPE   4
#define ANAT_CT_STR   "CT Scan"
#define ANAT_CT_PREFIX   "ct"
#define ANAT_CT_MASK   (1 << ANAT_CT_TYPE)
#define ANAT_SPECT_TYPE   5
#define ANAT_SPECT_STR   "SPECT Anatomy"
#define ANAT_SPECT_PREFIX   "spct"
#define ANAT_SPECT_MASK   (1 << ANAT_SPECT_TYPE)
#define ANAT_PET_TYPE   6
#define ANAT_PET_STR   "PET Anatomy"
#define ANAT_PET_PREFIX   "pet"
#define ANAT_PET_MASK   (1 << ANAT_PET_TYPE)
#define ANAT_MRA_TYPE   7
#define ANAT_MRA_STR   "MR Angiography"
#define ANAT_MRA_PREFIX   "mra"
#define ANAT_MRA_MASK   (1 << ANAT_MRA_TYPE)
#define ANAT_BMAP_TYPE   8
#define ANAT_BMAP_STR   "B-field Map"
#define ANAT_BMAP_PREFIX   "bmap"
#define ANAT_BMAP_MASK   (1 << ANAT_BMAP_TYPE)
#define ANAT_DIFF_TYPE   9
#define ANAT_DIFF_STR   "Diffusion Map"
#define ANAT_DIFF_PREFIX   "diff"
#define ANAT_DIFF_MASK   (1 << ANAT_DIFF_TYPE)
#define ANAT_OMRI_TYPE   10
#define ANAT_OMRI_STR   "Other MRI"
#define ANAT_OMRI_PREFIX   "omri"
#define ANAT_OMRI_MASK   (1 << ANAT_OMRI_TYPE)
#define ANAT_BUCK_TYPE   11
#define ANAT_BUCK_STR   "Anat Bucket"
#define ANAT_BUCK_PREFIX   "abuc"
#define ANAT_BUCK_MASK   (1 << ANAT_BUCK_TYPE)
#define ANAT_MAPC_TYPE   12
#define ANAT_MAPC_STR   "Mapped Color"
#define ANAT_MAPC_PREFIX   "mapc"
#define ANAT_MAPC_MASK   (1 << ANAT_MAPC_TYPE)
#define FIRST_ANAT_TYPE   0
#define LAST_ANAT_TYPE   11
#define ANAT_ALL_MASK
#define NUM_DSET_TYPES   (LAST_FUNC_TYPE + LAST_ANAT_TYPE + 2)
#define LONGEST_ANAT_TYPESTR   strlen(ANAT_MRA_STR)
#define DSET_PREFIXSTR(ds)
#define DSET_FUNCLABEL(ds)
#define DSET_TYPESTR(ds)
#define DOOMED   665
#define DSET_MARK_FOR_DEATH(ds)   do{ if( ISVALID_DSET(ds) && ds->death_mark >= 0 ) ds->death_mark = DOOMED ; } while(0)
#define DSET_MARK_FOR_IMMORTALITY(ds)   do{ if( ISVALID_DSET(ds) ) ds->death_mark = -1 ; } while(0)
#define DSET_MARK_FOR_NORMAL(ds)   do{ if( ISVALID_DSET(ds) ) ds->death_mark = 0 ; } while(0)
#define DSET_IS_TCAT(ds)   (ISVALID_DSET(ds) && (ds)->tcat_list != NULL)
#define CURRENT_DAXES(ds)   (((ds)->wod_flag) ? ((ds)->wod_daxes) : ((ds)->daxes))
#define ISVALID_3DIM_DATASET(ds)
#define ISVALID_DSET   ISVALID_3DIM_DATASET
#define ISFUNCTYPE(nn)   ( (nn) == HEAD_FUNC_TYPE || (nn) == GEN_FUNC_TYPE )
#define ISFUNC(dset)   ( ISVALID_DSET(dset) && ISFUNCTYPE((dset)->type) )
#define ISANATTYPE(nn)   ( (nn) == HEAD_ANAT_TYPE || (nn) == GEN_ANAT_TYPE )
#define ISANAT(dset)   ( ISVALID_DSET(dset) && ISANATTYPE((dset)->type) )
#define ISHEADTYPE(nn)   ( (nn) == HEAD_ANAT_TYPE || (nn) == HEAD_FUNC_TYPE )
#define ISHEAD(dset)   ( ISVALID_DSET(dset) && ISHEADTYPE((dset)->type) )
#define ISANATBUCKET(dset)   ( ISANAT(dset) && (dset)->func_type == ANAT_BUCK_TYPE )
#define ISFUNCBUCKET(dset)   ( ISFUNC(dset) && (dset)->func_type == FUNC_BUCK_TYPE )
#define ISBUCKET(dset)   ( ISANATBUCKET(dset) || ISFUNCBUCKET(dset) )
#define DSET_ONDISK(ds)
#define DSET_IS_BRIK(ds)
#define DBLK_IS_MINC(db)
#define DSET_IS_MINC(ds)
#define DBLK_IS_ANALYZE(db)
#define DSET_IS_ANALYZE(ds)
#define DBLK_IS_CTFMRI(db)
#define DSET_IS_CTFMRI(ds)
#define DBLK_IS_CTFSAM(db)
#define DSET_IS_CTFSAM(ds)
#define DBLK_IS_1D(db)
#define DBLK_IS_3D(db)
#define DBLK_IS_NIFTI(db)
#define DSET_IS_1D(ds)
#define DSET_IS_3D(ds)
#define DSET_IS_NIFTI(ds)
#define DBLK_IS_VOLUMES(db)
#define DSET_IS_VOLUMES(ds)
#define DBLK_IS_MPEG(db)
#define DSET_IS_MPEG(ds)
#define DSET_WRITEABLE(ds)
#define DSET_COMPRESSED(ds)
#define PURGE_DSET(ds)
#define DSET_INMEMORY(ds)
#define DBLK_BRICK(db, iv)   ((db)->brick->imarr[(iv)])
#define DSET_BRICK(ds, iv)   DBLK_BRICK((ds)->dblk,(iv))
#define DBLK_BRICK_TYPE(db, iv)   (DBLK_BRICK((db),(iv))->kind)
#define DSET_BRICK_TYPE(ds, iv)   DBLK_BRICK_TYPE((ds)->dblk,(iv))
#define DBLK_BRICK_NVOX(db, iv)   (DBLK_BRICK((db),(iv))->nvox)
#define DBLK_ARRAY(db, iv)   mri_data_pointer( DBLK_BRICK((db),(iv)) )
#define DSET_ARRAY(ds, iv)   DBLK_ARRAY((ds)->dblk,(iv))
#define DSET_BRICK_ARRAY   DSET_ARRAY
#define DBLK_BRICK_ARRAY   DBLK_ARRAY
#define DBLK_BRICK_FACTOR(db, iv)   ((db)->brick_fac[(iv)])
#define DSET_BRICK_FACTOR(ds, iv)   DBLK_BRICK_FACTOR((ds)->dblk,(iv))
#define DBLK_BRICK_BYTES(db, iv)   ((db)->brick_bytes[iv])
#define DSET_BRICK_BYTES(ds, iv)   DBLK_BRICK_BYTES((ds)->dblk,(iv))
#define DSET_PRINCIPAL_VALUE(ds)
#define DSET_PRINCIPAL_INDEX   DSET_PRINCIPAL_VALUE
#define DSET_THRESH_VALUE(ds)   (ISANAT((ds)) ? -1 : FUNC_ival_thr[(ds)->func_type])
#define DSET_THRESH_INDEX   DSET_THRESH_VALUE
#define DSET_PREFIX(ds)
#define DSET_FILECODE(ds)
#define DSET_HEADNAME(ds)
#define DSET_BRIKNAME(ds)
#define DSET_BRICKNAME   DSET_BRIKNAME
#define DSET_DIRNAME(ds)
#define DSET_SESSNAME   DSET_DIRNAME
#define DSET_IDCODE(ds)   (&((ds)->idcode))
#define DSET_IDCODE_STR(ds)   ((ds)->idcode.str)
#define DBLK_BYTEORDER(db)   ((db)->diskptr->byte_order)
#define DSET_BYTEORDER(ds)   DBLK_BYTEORDER((ds)->dblk)
#define DSET_NUM_TIMES(ds)   ( ((ds)->taxis == NULL) ? 1 : (ds)->taxis->ntt )
#define HAS_TIMEAXIS(ds)   ( DSET_NUM_TIMES(ds) > 1 )
#define DSET_NVALS_PER_TIME(ds)   ( (ds)->dblk->nvals / DSET_NUM_TIMES(ds) )
#define DSET_NVALS(ds)   ( (ds)->dblk->nvals )
#define DSET_NVOX(ds)   ( (ds)->daxes->nxx * (ds)->daxes->nyy * (ds)->daxes->nzz )
#define DSET_NX(ds)   ((ds)->daxes->nxx)
#define DSET_NY(ds)   ((ds)->daxes->nyy)
#define DSET_NZ(ds)   ((ds)->daxes->nzz)
#define DSET_DX(ds)   ((ds)->daxes->xxdel)
#define DSET_DY(ds)   ((ds)->daxes->yydel)
#define DSET_DZ(ds)   ((ds)->daxes->zzdel)
#define DSET_XORG(ds)   ((ds)->daxes->xxorg)
#define DSET_YORG(ds)   ((ds)->daxes->yyorg)
#define DSET_ZORG(ds)   ((ds)->daxes->zzorg)
#define DSET_XXMIN(ds)   ((ds)->daxes->xxmin)
#define DSET_XXMAX(ds)   ((ds)->daxes->xxmax)
#define DSET_YYMIN(ds)   ((ds)->daxes->yymin)
#define DSET_YYMAX(ds)   ((ds)->daxes->yymax)
#define DSET_ZZMIN(ds)   ((ds)->daxes->zzmin)
#define DSET_ZZMAX(ds)   ((ds)->daxes->zzmax)
#define DSET_index_to_ix(ds, ii)   ( (ii) % (ds)->daxes->nxx)
#define DSET_index_to_jy(ds, ii)   ( ((ii) / (ds)->daxes->nxx) % (ds)->daxes->nyy )
#define DSET_index_to_kz(ds, ii)   ( (ii) /((ds)->daxes->nxx * (ds)->daxes->nyy ))
#define DSET_ixyz_to_index(ds, ix, jy, kz)   ((ix)+((jy)+(kz)*(ds)->daxes->nyy)*(ds)->daxes->nxx)
#define DSET_CUBICAL(ds)
#define DSET_GRAPHABLE(ds)
#define DSET_TIMESTEP(ds)   ( ((ds)->taxis == NULL) ? 0.0 : (ds)->taxis->ttdel )
#define DSET_TR   DSET_TIMESTEP
#define DSET_TIMEORIGIN(ds)   ( ((ds)->taxis == NULL) ? 0.0 : (ds)->taxis->ttorg )
#define DSET_TIMEDURATION(ds)   ( ((ds)->taxis == NULL) ? 0.0 : (ds)->taxis->ttdur )
#define DSET_TIMEUNITS(ds)
#define DSET_NUM_TTOFF(ds)   ( ((ds)->taxis == NULL) ? 0 : (ds)->taxis->nsl )
#define DBLK_BRICK_LAB(db, iv)   ( ((db)->brick_lab != NULL) ? ((db)->brick_lab[iv]) : "?" )
#define DSET_BRICK_LAB(ds, iv)   DBLK_BRICK_LAB((ds)->dblk,(iv))
#define DSET_BRICK_LABEL   DSET_BRICK_LAB
#define DBLK_BRICK_STATCODE(db, iv)   ( ((db)->brick_statcode != NULL) ? (db)->brick_statcode[iv] : ILLEGAL_TYPE )
#define DSET_BRICK_STATCODE(ds, iv)
#define DBLK_BRICK_STATAUX(db, iv)   ( ((db)->brick_stataux != NULL) ? (db)->brick_stataux[iv] : NULL )
#define DSET_BRICK_STATAUX(ds, iv)
#define DBLK_BRICK_STATPAR(db, iv, jj)   ( ((db)->brick_stataux != NULL) ? (db)->brick_stataux[iv][jj] : 0.0 )
#define DSET_BRICK_STATPAR(ds, iv, jj)
#define DBLK_BRICK_KEYWORDS(db, iv)   ( ((db)->brick_keywords != NULL) ? ((db)->brick_keywords[iv]) : NULL )
#define DSET_BRICK_KEYWORDS(ds, iv)   DBLK_BRICK_KEYWORDS((ds)->dblk,(iv))
#define DSET_KEYWORDS(ds)   ((ds)->keywords)
#define DSET_BRICK_KEYWORDS_HAS(ds, iv, ss)   THD_string_has( DSET_BRICK_KEYWORDS((ds),(iv)) , (ss) )
#define DSET_KEYWORDS_HAS(ds, ss)   THD_string_has( DSET_KEYWORDS((ds)) , (ss) )
#define DSET_FIX_NAMES(ds)
#define RELOAD_STATS(dset)
#define DSET_VALID_BSTAT(dset, ii)
#define DSET_CRUSH_BSTAT(dset, ii)
#define DSET_KILL_STATS(ds)
#define INIT_STAT_AUX(ds, nf, ff)
#define ZERO_STAT_AUX(ds)
#define DSET_load(ds)   THD_load_datablock( (ds)->dblk )
#define DSET_unload(ds)   THD_purge_datablock( (ds)->dblk , DATABLOCK_MEM_ANY )
#define DSET_unload_one(ds, iv)   THD_purge_one_brick( (ds)->dblk , (iv) )
#define DSET_delete(ds)   THD_delete_3dim_dataset((ds),False)
#define DSET_write(ds)
#define DSET_write_header(ds)   THD_write_3dim_dataset( NULL,NULL , (ds),False )
#define DSET_LOADED(ds)   ( THD_count_databricks((ds)->dblk) == DSET_NVALS(ds) )
#define DSET_lock(ds)   DBLK_lock((ds)->dblk)
#define DSET_unlock(ds)   DBLK_unlock((ds)->dblk)
#define DSET_LOCKED(ds)   DBLK_LOCKED((ds)->dblk)
#define DSET_mallocize(ds)   DBLK_mallocize((ds)->dblk)
#define DSET_mmapize(ds)   DBLK_mmapize((ds)->dblk)
#define DSET_shareize(ds)   DBLK_shareize((ds)->dblk)
#define DSET_anyize(ds)   DBLK_anyize((ds)->dblk)
#define DSET_superlock(ds)   DBLK_superlock((ds)->dblk)
#define DSET_IS_MALLOC(ds)   DBLK_IS_MALLOC((ds)->dblk)
#define DSET_IS_MMAP(ds)   DBLK_IS_MMAP((ds)->dblk)
#define DSET_IS_SHARED(ds)   DBLK_IS_SHARED((ds)->dblk)
#define DSET_IS_MASTERED(ds)   DBLK_IS_MASTERED((ds)->dblk)
#define TWOGIG   2147000000
#define DBLK_mmapfix(db)
#define INC_3DARR   8
#define INIT_3DARR(name)
#define ADDTO_3DARR(name, ddset)
#define FREE_3DARR(name)
#define DSET_IN_3DARR(name, nn)   ((name)->ar[(nn)])
#define DSET_ORDERED(d1, d2)
#define DSET_SWAP(d1, d2)   (dt=(d1),(d1)=(d2),(d2)=dt)
#define SORT_3DARR(name)
#define SESSION_TYPE   97
#define ISVALID_SESSION(ss)   ( (ss) != NULL && (ss)->type == SESSION_TYPE )
#define BLANK_SESSION(ss)
#define SESSION_HAS_SUMA(ss)
#define SESSIONLIST_TYPE   107
#define ISVALID_SESSIONLIST(sl)   ( (sl)!=NULL && (sl)->type==SESSIONLIST_TYPE )
#define BLANK_SESSIONLIST(sl)
#define BADFIND(ff)
#define FIND_NAME   1
#define FIND_IDCODE   2
#define FIND_PREFIX   3
#define ATRNAME_DATANAME   "DATASET_NAME"
#define ATRNAME_LABEL1   "LABEL_1"
#define ATRNAME_LABEL2   "LABEL_2"
#define ATRNAME_ANATOMY_PARENT   "ANATOMY_PARENTNAME"
#define ATRNAME_ORIENT_SPECIFIC   "ORIENT_SPECIFIC"
#define ATRTYPE_ORIENT_SPECIFIC   ATR_INT_TYPE
#define ATRSIZE_ORIENT_SPECIFIC   3
#define ATRNAME_ORIENT_GENERAL   "ORIENT_GENERAL" /*** not used yet ***/
#define ATRTYPE_ORIENT_GENERAL   ATR_FLOAT_TYPE
#define ATRSIZE_ORIENT_GENERAL   9
#define ATRNAME_ORIGIN   "ORIGIN"
#define ATRTYPE_ORIGIN   ATR_FLOAT_TYPE
#define ATRSIZE_ORIGIN   3
#define ATRNAME_DELTA   "DELTA"
#define ATRTYPE_DELTA   ATR_FLOAT_TYPE
#define ATRSIZE_DELTA   3
#define ATRNAME_SKIP   "SKIP"
#define ATRTYPE_SKIP   ATR_FLOAT_TYPE
#define ATRSIZE_SKIP   3
#define ATRNAME_MARKSXYZ   "MARKS_XYZ"
#define ATRTYPE_MARKSXYZ   ATR_FLOAT_TYPE
#define ATRSIZE_MARKSXYZ   MARKS_FSIZE
#define ATRNAME_MARKSLAB   "MARKS_LAB"
#define ATRTYPE_MARKSLAB   ATR_STRING_TYPE
#define ATRSIZE_MARKSLAB   MARKS_LSIZE
#define ATRNAME_MARKSHELP   "MARKS_HELP"
#define ATRTYPE_MARKSHELP   ATR_STRING_TYPE
#define ATRSIZE_MARKSHELP   MARKS_HSIZE
#define ATRNAME_MARKSFLAG   "MARKS_FLAGS"
#define ATRTYPE_MARKSFLAG   ATR_INT_TYPE
#define ATRSIZE_MARKSFLAG   MARKS_MAXFLAG
#define ATRNAME_TYPESTRING   "TYPESTRING"
#define ATRTYPE_TYPESTRING   ATR_STRING_TYPE
#define ATRSIZE_TYPESTRING   0
#define ATRNAME_WARP_TYPE   "WARP_TYPE"
#define ATRTYPE_WARP_TYPE   ATR_INT_TYPE
#define ATRSIZE_WARP_TYPE   8
#define ATRNAME_WARP_DATA   "WARP_DATA"
#define ATRTYPE_WARP_DATA   ATR_FLOAT_TYPE
#define ATRSIZE_WARP_DATA   0
#define ATRNAME_WARP_PARENT   "WARP_PARENTNAME"
#define ATRTYPE_WARP_PARENT   ATR_STRING_TYPE
#define ATRSIZE_WARP_PARENT   0
#define ATRNAME_SCENE_TYPE   "SCENE_DATA"
#define ATRTYPE_SCENE_TYPE   ATR_INT_TYPE
#define ATRSIZE_SCENE_TYPE   8
#define ATRNAME_DATASET_RANK   "DATASET_RANK"
#define ATRTYPE_DATASET_RANK   ATR_INT_TYPE
#define ATRSIZE_DATASET_RANK   8
#define ATRNAME_DATASET_DIMENSIONS   "DATASET_DIMENSIONS"
#define ATRTYPE_DATASET_DIMENSIONS   ATR_INT_TYPE
#define ATRSIZE_DATASET_DIMENSIONS   THD_MAX_RANK_EVER
#define ATRNAME_MINMAX   "MINMAX"
#define ATRTYPE_MINMAX   ATR_INT_TYPE
#define ATRNAME_BRICK_TYPES   "BRICK_TYPES"
#define ATRTYPE_BRICK_TYPES   ATR_INT_TYPE
#define ATRSIZE_BRICK_TYPES   0
#define ATRNAME_BRICK_STATS   "BRICK_STATS"
#define ATRTYPE_BRICK_STATS   ATR_FLOAT_TYPE
#define ATRSIZE_BRICK_STATS   0
#define ATRNAME_BRICK_FLTFAC   "BRICK_FLOAT_FACS"
#define ATRTYPE_BRICK_FLTFAC   ATR_FLOAT_TYPE
#define ATRSIZE_BRICK_FLTFAC   0
#define ATRNAME_STAT_AUX   "STAT_AUX"
#define ATRTYPE_STAT_AUX   ATR_FLOAT_TYPE
#define ATRSIZE_STAT_AUX   0
#define ATRNAME_TAXIS_NUMS   "TAXIS_NUMS"
#define ATRSIZE_TAXIS_NUMS   8
#define ATRNAME_TAXIS_FLOATS   "TAXIS_FLOATS"
#define ATRSIZE_TAXIS_FLOATS   8
#define ATRNAME_TAXIS_OFFSETS   "TAXIS_OFFSETS"
#define ATRSIZE_TAXIS_OFFSETS   0
#define ATRNAME_BRICK_LABS   "BRICK_LABS"
#define ATRNAME_BRICK_STATAUX   "BRICK_STATAUX"
#define ATRNAME_BRICK_KEYWORDS   "BRICK_KEYWORDS"
#define ATRNAME_KEYWORDS   "DATASET_KEYWORDS"
#define THD_set_string_atr(blk, name, str)   THD_set_char_atr( (blk) , (name) , strlen(str)+1 , (str) )
#define MASTER_SHORTHELP_STRING
#define MASTER_HELP_STRING
#define CALC_HELP_STRING
#define TS_HELP_STRING
#define OKHOST(hh)   TRUST_host(hh) ;
#define DSET_datum_constant(ds)   THD_datum_constant((ds)->dblk)
#define ALLOW_FSL_FEAT
#define MINC_FLOATIZE_MASK   1
#define MISMATCH_CENTER   (1<<0)
#define MISMATCH_DELTA   (1<<1)
#define MISMATCH_ORIENT   (1<<2)
#define MISMATCH_DIMEN   (1<<3)
#define ROT3(a, b, c, na, nb, nc)   ((na)=(b),(nb)=(c),(nc)=(a))
#define BRICK_DRAWABLE(br)   ((br)->n1 > 1 && (br)->n2 > 1)
#define BRICK_GRAPHABLE(br)   ((br)->n1 >= 1 && (br)->n2 >= 1)
#define DETREND_linear(n, f)   THD_linear_detrend(n,f,NULL,NULL)
#define DETREND_quadratic(n, f)   THD_quadratic_detrend(n,f,NULL,NULL,NULL)
#define DETREND_cubic(n, f)   THD_cubic_detrend(n,f)
#define DETREND_const(n, f)   THD_const_detrend(n,f,NULL)
#define DETREND_polort(p, n, f)
#define DELTA_AFTER   1
#define DELTA_BEFORE   2
#define DELTA_FIXED   3
#define TM_IXY   2
#define TM_IYZ   0
#define TM_IZX   1
#define TM_ZLINE(tm, i)   (tm==NULL || tm->mask[TM_IXY][i])
#define TM_YLINE(tm, i)   (tm==NULL || tm->mask[TM_IZX][i])
#define TM_XLINE(tm, i)   (tm==NULL || tm->mask[TM_IYZ][i])
#define ZPAD_EMPTY   (1<<0)
#define ZPAD_PURGE   (1<<1)
#define ZPAD_MM   (1<<2)
#define WARP3D_NEWGRID   1
#define WARP3D_NEWDSET   2
#define WARP3D_GRIDMASK   7
#define MAX_DSET_NOTES   999
#define MAX_NOTE_SIZE   4000
#define AFNI_log_string(ss)   AFNI_logger(ss,0,NULL)
#define tross_Erase_History(ds)   THD_erase_one_atr((ds)->dblk,"HISTORY_NOTE")
#define TT_ATLAS_NZ_SMALL   141
#define TT_ATLAS_NZ_BIG   151
#define TT_retrieve_atlas_nz(nz)
#define SBFLAG_INDEX   (1<<0)
#define SBFLAG_FACTOR   (1<<1)
#define SBFLAG_STATCODE   (1<<2)

Typedefs

typedef void generic_func ()
typedef float float_func ()
typedef THD_3dim_dataset THD_3dim_dataset
typedef THD_3dim_dataset_array THD_3dim_dataset_array
typedef FD_brick FD_brick

Functions

int SARR_find_string (THD_string_array *sar, char *str)
int SARR_find_substring (THD_string_array *sar, char *sub)
int SARR_lookfor_string (THD_string_array *sar, char *str, int nstart)
int SARR_lookfor_substring (THD_string_array *sar, char *sub, int nstart)
void THD_zblock (int, char *)
void THD_unzblock (int, char *)
void THD_delete_diskptr (THD_diskptr *)
void THD_delete_datablock (THD_datablock *)
void THD_init_datablock_brick (THD_datablock *, int, void *)
void THD_init_datablock_labels (THD_datablock *)
void THD_init_datablock_keywords (THD_datablock *)
void THD_copy_datablock_auxdata (THD_datablock *, THD_datablock *)
void THD_init_datablock_stataux (THD_datablock *)
void THD_store_datablock_stataux (THD_datablock *, int, int, int, float *)
void THD_store_datablock_label (THD_datablock *, int, char *)
void THD_store_datablock_keywords (THD_datablock *, int, char *)
void THD_append_datablock_keywords (THD_datablock *, int, char *)
int THD_datablock_from_atr (THD_datablock *, char *, char *)
int THD_string_has (char *, char *)
void THD_edit_dataxes (float, THD_dataxes *, THD_dataxes *)
int THD_get_axis_direction (THD_dataxes *, int)
void MCW_hash_idcode (char *, struct THD_3dim_dataset *)
void THD_coorder_fill (char *, THD_coorder *)
void THD_dicom_to_coorder (THD_coorder *, float *, float *, float *)
void THD_coorder_to_dicom (THD_coorder *, float *, float *, float *)
int THD_need_brick_factor (THD_3dim_dataset *)
char * THD_newprefix (THD_3dim_dataset *dset, char *suffix)
char * THD_deplus_prefix (char *prefix)
char * ig_strstr (char *, char *, char *)
void freeup_strings (int n, char **sar)
int breakup_string (char *sin, char ***stok)
THD_string_arrayTHD_get_all_filenames (char *)
THD_string_arrayTHD_extract_regular_files (THD_string_array *)
THD_string_arrayTHD_extract_directories (THD_string_array *)
int THD_is_file (char *)
int THD_is_symlink (char *)
int THD_is_directory (char *)
int THD_is_ondisk (char *)
int THD_mkdir (char *)
int THD_cwd (char *)
int THD_equiv_files (char *, char *)
unsigned long THD_filesize (char *pathname)
THD_string_arrayTHD_get_all_subdirs (int, char *)
THD_string_arrayTHD_normalize_flist (THD_string_array *)
THD_string_arrayTHD_get_wildcard_filenames (char *)
time_t THD_file_mtime (char *)
THD_string_arrayTHD_get_all_executables (char *)
THD_string_arrayTHD_getpathprogs (THD_string_array *)
int THD_is_executable (char *pathname)
char * THD_find_executable (char *)
int THD_is_dataset (char *, char *, int)
char * THD_dataset_headname (char *, char *, int)
MRI_IMARRTHD_get_all_timeseries (char *)
MRI_IMARRTHD_get_many_timeseries (THD_string_array *)
char * THD_trailname (char *fname, int lev)
int THD_linecount (char *)
void THD_read_all_atr (char *, THD_datablock *)
void THD_erase_all_atr (THD_datablock *)
void THD_erase_one_atr (THD_datablock *, char *)
void THD_read_niml_atr (char *, THD_datablock *)
void THD_anonymize_dset (THD_3dim_dataset *)
void THD_anonymize_write (int)
ATR_anyTHD_find_atr (THD_datablock *, char *)
ATR_floatTHD_find_float_atr (THD_datablock *, char *)
ATR_intTHD_find_int_atr (THD_datablock *, char *)
ATR_stringTHD_find_string_atr (THD_datablock *, char *)
void THD_set_atr (THD_datablock *, char *, int, int, void *)
ATR_anyTHD_copy_atr (ATR_any *atr)
void THD_insert_atr (THD_datablock *blk, ATR_any *atr)
void THD_store_dataset_keywords (THD_3dim_dataset *, char *)
void THD_append_dataset_keywords (THD_3dim_dataset *, char *)
char * THD_dataset_info (THD_3dim_dataset *, int)
char * THD_zzprintf (char *sss, char *fmt,...)
void THD_set_float_atr (THD_datablock *, char *, int, float *)
void THD_set_int_atr (THD_datablock *, char *, int, int *)
void THD_set_char_atr (THD_datablock *, char *, int, char *)
void THD_init_diskptr_names (THD_diskptr *, char *, char *, char *, int, Boolean)
THD_datablockTHD_init_one_datablock (char *, char *)
THD_datablock_arrayTHD_init_prefix_datablocks (char *, THD_string_array *)
XtPointer_arrayTHD_init_alldir_datablocks (char *)
THD_sessionTHD_init_session (char *)
void THD_order_session (THD_session *)
THD_3dim_datasetTHD_open_one_dataset (char *)
THD_3dim_datasetTHD_open_dataset (char *)
THD_3dim_datasetTHD_open_minc (char *)
THD_3dim_datasetTHD_open_analyze (char *)
THD_3dim_datasetTHD_open_ctfmri (char *)
THD_3dim_datasetTHD_open_ctfsam (char *)
THD_3dim_datasetTHD_open_1D (char *)
THD_3dim_datasetTHD_open_3D (char *)
THD_3dim_datasetTHD_open_nifti (char *)
THD_3dim_datasetTHD_open_mpeg (char *)
THD_3dim_datasetTHD_open_tcat (char *)
void THD_datablock_apply_atr (THD_3dim_dataset *)
THD_3dim_datasetTHD_fetch_dataset (char *)
XtPointer_arrayTHD_fetch_many_datasets (char *)
MRI_IMAGETHD_fetch_1D (char *)
void THD_set_storage_mode (THD_3dim_dataset *, int)
int * MCW_get_intlist (int, char *)
void MCW_intlist_allow_negative (int)
THD_3dim_datasetTHD_copy_dset_subs (THD_3dim_dataset *, int *)
void THD_delete_3dim_dataset (THD_3dim_dataset *, Boolean)
THD_3dim_datasetTHD_3dim_from_block (THD_datablock *)
void THD_allow_empty_dataset (int)
THD_3dim_dataset_arrayTHD_array_3dim_from_block (THD_datablock_array *blk_arr)
Boolean THD_write_3dim_dataset (char *, char *, THD_3dim_dataset *, Boolean)
void THD_use_3D_format (int)
void THD_use_NIFTI_format (int)
Boolean THD_write_datablock (THD_datablock *, Boolean)
Boolean THD_write_atr (THD_datablock *)
Boolean THD_write_nimlatr (THD_datablock *)
void THD_set_write_compression (int mm)
int THD_enviro_write_compression (void)
int THD_get_write_compression (void)
void THD_set_write_order (int)
void THD_enviro_write_order (void)
int THD_get_write_order (void)
int TRUST_host (char *)
void TRUST_addhost (char *)
Boolean THD_load_datablock (THD_datablock *)
void THD_load_datablock_verbose (int)
void THD_set_freeup (generic_func *)
Boolean THD_purge_datablock (THD_datablock *, int)
Boolean THD_purge_one_brick (THD_datablock *, int)
void THD_force_malloc_type (THD_datablock *, int)
int THD_count_databricks (THD_datablock *dblk)
void THD_load_minc (THD_datablock *)
void THD_load_analyze (THD_datablock *)
void THD_load_ctfmri (THD_datablock *)
void THD_load_ctfsam (THD_datablock *)
void THD_load_1D (THD_datablock *)
void THD_load_3D (THD_datablock *)
void THD_load_nifti (THD_datablock *)
void THD_load_mpeg (THD_datablock *)
void THD_load_tcat (THD_datablock *)
void THD_zerofill_dataset (THD_3dim_dataset *)
int THD_datum_constant (THD_datablock *)
int THD_write_minc (char *, THD_3dim_dataset *, int)
void THD_write_1D (char *, char *, THD_3dim_dataset *)
void THD_write_3D (char *, char *, THD_3dim_dataset *)
void THD_reconcile_parents (THD_sessionlist *)
THD_slist_find THD_dset_in_sessionlist (int, void *, THD_sessionlist *, int)
THD_slist_find THD_dset_in_session (int, void *, THD_session *)
void THD_check_idcodes (THD_sessionlist *)
void THD_load_statistics (THD_3dim_dataset *)
void THD_update_statistics (THD_3dim_dataset *)
void THD_update_one_bstat (THD_3dim_dataset *, int)
THD_fvec3 THD_3dind_to_3dmm (THD_3dim_dataset *, THD_ivec3)
THD_fvec3 THD_3dind_to_3dmm_no_wod (THD_3dim_dataset *, THD_ivec3)
THD_ivec3 THD_3dmm_to_3dind (THD_3dim_dataset *, THD_fvec3)
THD_ivec3 THD_3dmm_to_3dind_no_wod (THD_3dim_dataset *, THD_fvec3)
THD_fvec3 THD_3dfind_to_3dmm (THD_3dim_dataset *, THD_fvec3)
THD_fvec3 THD_3dmm_to_3dfind (THD_3dim_dataset *, THD_fvec3)
THD_fvec3 THD_3dmm_to_dicomm (THD_3dim_dataset *, THD_fvec3)
THD_fvec3 THD_dicomm_to_3dmm (THD_3dim_dataset *, THD_fvec3)
THD_fvec3 THD_tta_to_mni (THD_fvec3)
THD_fvec3 THD_mni_to_tta (THD_fvec3)
void THD_3mni_to_3tta (float *, float *, float *)
void THD_3tta_to_3mni (float *, float *, float *)
float THD_timeof (int, float, THD_timeaxis *)
float THD_timeof_vox (int, int, THD_3dim_dataset *)
float THD_timeof_slice (int, int, THD_3dim_dataset *)
int THD_dataset_mismatch (THD_3dim_dataset *, THD_3dim_dataset *)
int THD_dataset_tshift (THD_3dim_dataset *, int)
FD_brickTHD_3dim_dataset_to_brick (THD_3dim_dataset *, int, int, int)
MRI_IMAGEFD_brick_to_mri (int, int, FD_brick *br)
MRI_IMAGEFD_brick_to_series (int, FD_brick *br)
float THD_get_voxel (THD_3dim_dataset *dset, int ijk, int ival)
MRI_IMAGETHD_extract_series (int, THD_3dim_dataset *, int)
MRI_IMARRTHD_extract_many_series (int, int *, THD_3dim_dataset *)
int THD_extract_array (int, THD_3dim_dataset *, int, void *)
MRI_IMAGETHD_extract_float_brick (int, THD_3dim_dataset *)
void THD_insert_series (int, THD_3dim_dataset *, int, int, void *, int)
void get_linear_trend (int, float *, float *, float *)
void THD_linear_detrend (int, float *, float *, float *)
void get_quadratic_trend (int, float *, float *, float *, float *)
void THD_quadratic_detrend (int, float *, float *, float *, float *)
void THD_normalize (int, float *)
void THD_cubic_detrend (int, float *)
void THD_const_detrend (int, float *, float *)
void THD_generic_detrend (int, float *, int, int, float **)
THD_ivec3 THD_fdind_to_3dind (FD_brick *, THD_ivec3)
THD_ivec3 THD_3dind_to_fdind (FD_brick *, THD_ivec3)
THD_fvec3 THD_fdfind_to_3dfind (FD_brick *, THD_fvec3)
THD_fvec3 THD_3dfind_to_fdfind (FD_brick *, THD_fvec3)
FD_brick ** THD_setup_bricks (THD_3dim_dataset *)
FD_brickTHD_oriented_brick (THD_3dim_dataset *, char *)
int thd_floatscan (int, float *)
int thd_complexscan (int, complex *)
byteTHD_makemask (THD_3dim_dataset *, int, float, float)
int THD_countmask (int, byte *)
byteTHD_automask (THD_3dim_dataset *)
void THD_automask_verbose (int)
void THD_automask_extclip (int)
bytemri_automask_image (MRI_IMAGE *)
bytemri_automask_imarr (MRI_IMARR *)
void THD_autobbox (THD_3dim_dataset *, int *, int *, int *, int *, int *, int *)
void MRI_autobbox (MRI_IMAGE *, int *, int *, int *, int *, int *, int *)
int THD_mask_fillin_completely (int, int, int, byte *, int)
int THD_mask_fillin_once (int, int, int, byte *, int)
int THD_mask_clip_neighbors (int, int, int, byte *, float, float, float *)
void THD_mask_clust (int nx, int ny, int nz, byte *mmm)
void THD_mask_erode (int nx, int ny, int nz, byte *mmm)
int THD_peel_mask (int nx, int ny, int nz, byte *mmm, int pdepth)
void THD_mask_dilate (int, int, int, byte *, int)
float THD_cliplevel (MRI_IMAGE *, float)
MRI_IMAGETHD_median_brick (THD_3dim_dataset *)
MRI_IMAGETHD_mean_brick (THD_3dim_dataset *)
MRI_IMAGETHD_rms_brick (THD_3dim_dataset *)
int THD_get_dset_rowcount (THD_3dim_dataset *, int)
void * THD_get_dset_row (THD_3dim_dataset *, int, int, int, int, int)
void THD_put_dset_row (THD_3dim_dataset *, int, int, int, int, int, void *row)
int THD_dataset_rowfillin (THD_3dim_dataset *, int, int, int)
int THD_dataset_zfillin (THD_3dim_dataset *, int, int, int)
void THD_rotangle_user_to_dset (THD_3dim_dataset *, float, char, float, char, float, char, float *, int *, float *, int *, float *, int *)
int THD_axcode (THD_3dim_dataset *, char)
int THD_handedness (THD_3dim_dataset *)
THD_dvecmat THD_rotcom_to_matvec (THD_3dim_dataset *, char *)
void THD_rota_method (int)
void THD_rota_setpad (int, int, int)
void THD_rota_clearpad (void)
void THD_rota_vol (int, int, int, float, float, float, float *, int, float, int, float, int, float, int, float, float, float)
MRI_IMAGETHD_rota3D (MRI_IMAGE *, int, float, int, float, int, float, int, float, float, float)
MRI_IMAGETHD_rota3D_matvec (MRI_IMAGE *, THD_dmat33, THD_dfvec3)
void THD_rota_vol_matvec (int, int, int, float, float, float, float *, THD_dmat33, THD_dfvec3)
THD_dvecmat DLSQ_rot_trans (int, THD_dfvec3 *, THD_dfvec3 *, double *)
THD_dvecmat DLSQ_affine (int, THD_dfvec3 *, THD_dfvec3 *)
THD_dvecmat DLSQ_rotscl (int, THD_dfvec3 *, THD_dfvec3 *, int)
THD_dvecmat THD_read_dvecmat (char *, int)
void free_Tmask (Tmask *)
Tmaskcreate_Tmask_byte (int, int, int, byte *)
Tmaskcreate_Tmask_rgba (int, int, int, rgba *)
void THD_rota_vol_byte (int, int, int, float, float, float, byte *, int, float, int, float, int, float, int, float, float, float, Tmask *)
void THD_rota_byte_mode (int)
void THD_rota_vol_matvec_byte (int, int, int, float, float, float, byte *, THD_mat33, THD_fvec3, Tmask *)
void SHIFT_set_method (int)
int SHIFT_get_method (void)
void SHIFT_two_rows (int, int, float, float *, float, float *)
void fft_shift2 (int, int, float, float *, float, float *)
void hept_shift2 (int, int, float, float *, float, float *)
void quint_shift2 (int, int, float, float *, float, float *)
void cub_shift2 (int, int, float, float *, float, float *)
void lin_shift2 (int, int, float, float *, float, float *)
void nn_shift2 (int, int, float, float *, float, float *)
void ts_shift2 (int, int, float, float *, float, float *)
void hept_shift (int, float, float *)
void nn_shift (int, float, float *)
void lin_shift (int, float, float *)
void cub_shift (int, float, float *)
void quint_shift (int, float, float *)
void THD_fftshift (THD_3dim_dataset *, float, float, float, int)
void mri_3dalign_edging (int, int, int)
void mri_3dalign_edging_default (int, int, int)
void mri_3dalign_force_edging (int)
void mri_3dalign_wtrimming (int)
void mri_3dalign_wproccing (int)
void mri_3dalign_scaleinit (float)
void mri_3dalign_params (int, float, float, float, int, int, int, int)
void mri_3dalign_method (int, int, int, int)
void mri_3dalign_final_regmode (int)
MRI_3dalign_basismri_3dalign_setup (MRI_IMAGE *, MRI_IMAGE *)
MRI_IMAGEmri_3dalign_one (MRI_3dalign_basis *, MRI_IMAGE *, float *, float *, float *, float *, float *, float *)
MRI_IMARRmri_3dalign_many (MRI_IMAGE *, MRI_IMAGE *, MRI_IMARR *, float *, float *, float *, float *, float *, float *)
void mri_3dalign_cleanup (MRI_3dalign_basis *)
void mri_3dalign_initvals (float, float, float, float, float, float)
int mri_warp3D_align_setup (MRI_warp3D_align_basis *)
MRI_IMAGEmri_warp3d_align_one (MRI_warp3D_align_basis *, MRI_IMAGE *)
void mri_warp3D_align_cleanup (MRI_warp3D_align_basis *)
float THD_stat_to_pval (float thr, int statcode, float *stataux)
float THD_pval_to_stat (float pval, int statcode, float *stataux)
float THD_stat_to_zscore (float thr, int statcode, float *stataux)
int THD_filename_ok (char *)
int THD_filename_pure (char *)
int THD_freemegabytes (char *)
THD_warpAFNI_make_voxwarp (THD_warp *, THD_3dim_dataset *, THD_3dim_dataset *)
THD_linear_mappingAFNI_make_voxmap (THD_linear_mapping *, THD_dataxes *, THD_dataxes *)
void AFNI_concatenate_warp (THD_warp *, THD_warp *)
THD_linear_mappingAFNI_concatenate_lmap (THD_linear_mapping *, THD_linear_mapping *)
THD_warpAFNI_make_affwarp_12 (float, float, float, float, float, float, float, float, float, float, float, float)
THD_warpAFNI_make_affwarp_mat (THD_mat33)
THD_warpAFNI_make_affwarp_matvec (THD_mat33, THD_fvec3)
THD_ivec3 THD_matrix_to_orientation (THD_mat33 R)
THD_3dim_datasetWINsorize (THD_3dim_dataset *, int, int, int, float, char *, int, int, byte *)
THD_3dim_datasetTHD_zeropad (THD_3dim_dataset *, int, int, int, int, int, int, char *, int)
THD_3dim_datasetTHD_warp3D (THD_3dim_dataset *, void w_in2out(float, float, float, float *, float *, float *), void w_out2in(float, float, float, float *, float *, float *), void *, char *, int, int)
THD_3dim_datasetTHD_warp3D_affine (THD_3dim_dataset *, THD_vecmat, void *, char *, int, int)
THD_3dim_datasetTHD_warp3D_mni2tta (THD_3dim_dataset *, void *, char *, int, int)
THD_3dim_datasetTHD_warp3D_tta2mni (THD_3dim_dataset *, void *, char *, int, int)
void ENTROPY_setup (void)
void ENTROPY_setdown (void)
void ENTROPY_accumulate (int, void *)
double ENTROPY_compute (void)
double ENTROPY_dataset (THD_3dim_dataset *)
double ENTROPY_datablock (THD_datablock *)
void tross_Add_Note (THD_3dim_dataset *, char *)
void tross_Delete_Note (THD_3dim_dataset *, int)
char * tross_Expand_String (char *)
char * tross_Encode_String (char *)
void tross_Dont_Encode_Slash (int)
void tross_Store_Note (THD_3dim_dataset *, int, char *)
char * tross_Get_Note (THD_3dim_dataset *, int)
char * tross_Get_Notedate (THD_3dim_dataset *, int)
int tross_Get_Notecount (THD_3dim_dataset *)
void tross_Addto_History (THD_3dim_dataset *, THD_3dim_dataset *)
char * tross_datetime (void)
char * tross_username (void)
char * tross_hostname (void)
char * tross_commandline (char *, int, char **)
int AFNI_logger (char *, int, char **)
void AFNI_sleep (int)
void AFNI_serverlog (char *)
void THD_outlier_count (THD_3dim_dataset *, float, int **, int *)
void tross_Append_History (THD_3dim_dataset *, char *)
char * tross_Get_History (THD_3dim_dataset *)
void tross_Make_History (char *, int, char **, THD_3dim_dataset *)
void tross_Copy_History (THD_3dim_dataset *, THD_3dim_dataset *)
void tross_Replace_History (THD_3dim_dataset *, char *)
char * tross_breakup_string (char *, int, int)
void tross_multi_Append_History (THD_3dim_dataset *,...)
void B64_to_binary (int, byte *, int *, byte **)
void B64_to_base64 (int, byte *, int *, byte **)
void B64_set_linelen (int)
void B64_set_crlf (int)
char * MD5_static_array (int, char *)
char * MD5_malloc_array (int, char *)
char * MD5_static_string (char *)
char * MD5_malloc_string (char *)
char * MD5_static_file (char *)
char * MD5_malloc_file (char *)
char * MD5_B64_array (int, char *)
char * MD5_B64_string (char *)
char * MD5_B64_file (char *)
char * UNIQ_idcode (void)
void UNIQ_idcode_fill (char *)
char * TT_whereami (float, float, float)
int TT_load_atlas (void)
void TT_purge_atlas (void)
THD_3dim_datasetTT_retrieve_atlas (void)
THD_3dim_datasetTT_retrieve_atlas_big (void)
void TT_purge_atlas_big (void)
THD_3dim_datasetTT_retrieve_atlas_either (void)
float THD_spearman_corr (int, float *, float *)
float THD_quadrant_corr (int, float *, float *)
float THD_pearson_corr (int, float *, float *)
THD_fvec3 THD_autonudge (THD_3dim_dataset *dsepi, int ivepi, THD_3dim_dataset *dsant, int ivant, float step, int xstep, int ystep, int zstep, int code)
MRI_IMAGEmri_brainormalize (MRI_IMAGE *, int, int, int, MRI_IMAGE **, MRI_IMAGE **)
void mri_brainormalize_verbose (int)
void brainnormalize_coord (float ispat, float jspat, float kspat, float *iorig, float *jorig, float *korig, THD_3dim_dataset *origset, float *xrai_orig, float *yrai_orig, float *zrai_orig)
 takes in voxel indices into the Spat Normed volume (RAI) and returns voxel indices and coordinates in the original volume. Used to figure out shift to apply to surface model to align it with original volume.

MRI_IMAGEmri_watershedize (MRI_IMAGE *, float)
void mri_brainormalize_initialize (float dx, float dy, float dz)
float THD_BN_dxyz (void)
int THD_BN_nx (void)
int THD_BN_ny (void)
int THD_BN_nz (void)
NI_groupTHD_nimlize_dsetatr (THD_3dim_dataset *)
void THD_dblkatr_from_niml (NI_group *, THD_datablock *)
void THD_set_dataset_attributes (THD_3dim_dataset *)
THD_3dim_datasetTHD_niml_to_dataset (NI_group *, int)
int THD_add_bricks (THD_3dim_dataset *, void *)
NI_elementTHD_subbrick_to_niml (THD_3dim_dataset *, int, int)
NI_groupTHD_dataset_to_niml (THD_3dim_dataset *)
MRI_IMAGEniml_to_mri (NI_element *)
NI_elementmri_to_niml (MRI_IMAGE *)

Variables

char * ATR_typestr []
char * MAPPING_typestr []
int THD_align_aflags [MARKS_MAXFLAG]
char * THD_align_label [NMARK_ALIGN]
char * THD_align_help [NMARK_ALIGN]
int THD_bounding_aflags [MARKS_MAXFLAG]
char * THD_bounding_label [NMARK_BOUNDING]
char * THD_bounding_help [NMARK_BOUNDING]
char * WARP_typestr []
char * RESAM_typestr []
char * RESAM_shortstr [] = { "NN" , "Li" , "Cu" , "Bk" }
THD_warp tempA_warp
char * ORIENT_typestr []
char * ORIENT_shortstr []
char * ORIENT_tinystr []
char ORIENT_xyz [] = "xxyyzzg"
char ORIENT_sign [] = "+--++-"
char ORIENT_first [] = "RLPAIS"
int ORIENT_xyzint [] = { 1,1 , 2,2 , 3,3 , 666 }
char * UNITS_TYPE_labelstring [] = { "ms" , "s" , "Hz" }
MCW_idcode MCW_new_idcode (void)
char * DATASET_typestr []
char * VIEW_typestr []
char * VIEW_codestr []
char * FUNC_typestr []
char * FUNC_prefixstr []
float FUNC_topval []
int FUNC_scale_short []
int FUNC_scale_byte []
char * FUNC_label []
char * FUNC_descriptor []
int FUNC_nvals [] = { 1, 2,2,2,2,2,2,2,2,2,2, 1 }
int FUNC_ival_fim [] = { 0, 0,0,0,0,0,0,0,0,0,0, 0 }
int FUNC_ival_thr [] = { FIMTHR, 1,1,1,1,1,1,1,1,1,1, 0 }
int FUNC_need_stat_aux []
char * FUNC_label_stat_aux []
char * ANAT_typestr []
char * ANAT_prefixstr []
char * DSET_prefixstr [NUM_DSET_TYPES]
int ANAT_nvals [] = { 1,1,1,1,1,1,1,1,1,1,1,1 , 1 }
int ANAT_ival_zero [] = { 0,0,0,0,0,0,0,0,0,0,0,0 , 0 }
char tmp_dblab [8]
THD_brick_stats THD_get_brick_stats (MRI_IMAGE *)
THD_fvec3 THD_dataset_center (THD_3dim_dataset *)
THD_dmat33 DBLE_mat_to_dicomm (THD_3dim_dataset *)
THD_mat33 SNGL_mat_to_dicomm (THD_3dim_dataset *)

Detailed Description

This file contains the definition of the structs, macros, etc. for AFNI datasets.

Definition in file 3ddata.h.


Define Documentation

#define ADDTO_3DARR name,
ddset   
 

Value:

{ if( (name)->num == (name)->nall ){                               \
      (name)->nall += INC_3DARR ;                                     \
      (name)->ar    = (THD_3dim_dataset **)                           \
                       XtRealloc( (char *) (name)->ar ,               \
                        sizeof(THD_3dim_dataset *) * (name)->nall ) ; \
     }                                                             \
     if( (ddset) != NULL ){               \
      (name)->ar[(name)->num] = (ddset) ; \
      ((name)->num)++ ;                  \
     } }
Add dataset ddset to AFNI dataset array "name"

Definition at line 2780 of file 3ddata.h.

Referenced by B2F_read_opts(), BUCK_read_opts(), TCAT_read_opts(), THD_array_3dim_from_block(), and ZCAT_read_opts().

#define ADDTO_DBARR name,
bblk   
 

Value:

{ if( (name)->num == (name)->nall ){                            \
      (name)->nall += INC_DBARR ;                                  \
      (name)->ar    = (THD_datablock **)                           \
                       XtRealloc( (char *) (name)->ar ,            \
                        sizeof(THD_datablock *) * (name)->nall ) ; \
     }                                                             \
     if( (bblk) != NULL ){               \
      (name)->ar[(name)->num] = (bblk) ; \
      ((name)->num)++ ;                  \
     } }
Add a datablock to a THD_datablock_array.

Definition at line 1172 of file 3ddata.h.

Referenced by THD_init_prefix_datablocks().

#define ADDTO_SARR name,
str   
 

Value:

do{ if( (name)->num == (name)->nall ){                               \
      (name)->nall += INC_SARR ;                                      \
      (name)->ar    = (char **) XtRealloc( (char *) (name)->ar ,      \
                                 sizeof(char *) * (name)->nall ) ;    \
     }                                                                \
     if( (str) != NULL ){                                             \
      (name)->ar[(name)->num] = (char *) XtMalloc( strlen((str))+1 ) ;\
      strcpy( (name)->ar[(name)->num] , (str) ) ;                     \
      ADDTO_KILL((name)->kl,(name)->ar[(name)->num]) ;                \
      ((name)->num)++ ;                                               \
     } } while(0)
Add string str to dynamic string array "name".

Definition at line 307 of file 3ddata.h.

Referenced by AFNI_read_inputs(), AFNI_rescan_timeseries_CB(), AFNI_write_many_dataset_CB(), ISQ_saver_CB(), MCW_stradd_CB(), NLFIT_get_many_MODELs(), PLUG_get_many_plugins(), T3D_read_images(), THD_extract_directories(), THD_extract_regular_files(), THD_get_all_executables(), THD_get_all_filenames(), THD_get_all_subdirs(), THD_get_many_timeseries(), THD_get_wildcard_filenames(), THD_getpathprogs(), THD_normalize_flist(), TT_read_opts(), and TT_whereami().

#define ADDTO_XTARR name,
bblk   
 

Value:

{ if( (name)->num == (name)->nall ){                        \
      (name)->nall += INC_XTARR ;                              \
      (name)->ar    = (XtPointer *)                            \
                       XtRealloc( (char *) (name)->ar ,        \
                          sizeof(XtPointer) * (name)->nall ) ; \
      (name)->ic    = (int *) XtRealloc( (char *) (name)->ic , \
                          sizeof(int) * (name)->nall ) ;       \
     }                                                         \
     if( (XtPointer) (bblk) != NULL ){               \
      (name)->ar[(name)->num] = (XtPointer) (bblk) ; \
      (name)->ic[(name)->num] = 0                  ; \
      ((name)->num)++ ;                              \
     } }
Add a pointer to a dynamic XtPointer array.

Definition at line 233 of file 3ddata.h.

Referenced by AFNI_add_interruptable(), AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), B2F_read_opts(), BUCK_read_opts(), TCAT_read_opts(), THD_fetch_many_datasets(), and THD_init_alldir_datablocks().

#define AFNI_FIRST_STATCODE   FUNC_COR_TYPE
 

Definition at line 1772 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), and THD_open_3D().

#define AFNI_LAST_STATCODE   FUNC_PT_TYPE
 

Definition at line 1773 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), and THD_open_3D().

#define AFNI_log_string ss       AFNI_logger(ss,0,NULL)
 

Definition at line 3823 of file 3ddata.h.

Referenced by T3D_initialize_user_data().

#define ALLOW_FSL_FEAT
 

Definition at line 3338 of file 3ddata.h.

#define ALLOW_MINC
 

Enables compilation of the MINC dataset code.

Definition at line 56 of file 3ddata.h.

#define ANAT_ALL_MASK
 

Value:

Definition at line 1903 of file 3ddata.h.

Referenced by CORREL_init(), and PLUGIN_init().

#define ANAT_BMAP_MASK   (1 << ANAT_BMAP_TYPE)
 

Definition at line 1878 of file 3ddata.h.

#define ANAT_BMAP_PREFIX   "bmap"
 

Definition at line 1877 of file 3ddata.h.

#define ANAT_BMAP_STR   "B-field Map"
 

Definition at line 1876 of file 3ddata.h.

#define ANAT_BMAP_TYPE   8
 

Definition at line 1875 of file 3ddata.h.

#define ANAT_BUCK_MASK   (1 << ANAT_BUCK_TYPE)
 

Definition at line 1893 of file 3ddata.h.

#define ANAT_BUCK_PREFIX   "abuc"
 

Definition at line 1892 of file 3ddata.h.

#define ANAT_BUCK_STR   "Anat Bucket"
 

Definition at line 1891 of file 3ddata.h.

#define ANAT_BUCK_TYPE   11
 

Definition at line 1890 of file 3ddata.h.

Referenced by EDIT_wod_copy(), main(), SUMA_BrainVoyager_Read_vmr(), SUMA_OpenDX_Read_CruiseVolHead(), THD_open_1D(), THD_open_3D(), THD_open_minc(), THD_open_nifti(), and THD_setup_mastery().

#define ANAT_CT_MASK   (1 << ANAT_CT_TYPE)
 

Definition at line 1858 of file 3ddata.h.

#define ANAT_CT_PREFIX   "ct"
 

Definition at line 1857 of file 3ddata.h.

#define ANAT_CT_STR   "CT Scan"
 

Definition at line 1856 of file 3ddata.h.

#define ANAT_CT_TYPE   4
 

Definition at line 1855 of file 3ddata.h.

#define ANAT_DIFF_MASK   (1 << ANAT_DIFF_TYPE)
 

Definition at line 1883 of file 3ddata.h.

#define ANAT_DIFF_PREFIX   "diff"
 

Definition at line 1882 of file 3ddata.h.

#define ANAT_DIFF_STR   "Diffusion Map"
 

Definition at line 1881 of file 3ddata.h.

#define ANAT_DIFF_TYPE   9
 

Definition at line 1880 of file 3ddata.h.

#define ANAT_EPI_MASK   (1 << ANAT_EPI_TYPE)
 

Definition at line 1848 of file 3ddata.h.

Referenced by PLUGIN_init().

#define ANAT_EPI_PREFIX   "epan"
 

Definition at line 1847 of file 3ddata.h.

#define ANAT_EPI_STR   "Echo Planar"
 

Definition at line 1846 of file 3ddata.h.

#define ANAT_EPI_TYPE   2
 

Definition at line 1845 of file 3ddata.h.

Referenced by AFNI_read_inputs(), main(), RT_start_dataset(), T3D_initialize_user_data(), THD_open_1D(), THD_open_3D(), THD_open_analyze(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), and THD_open_tcat().

#define ANAT_FSE_MASK   (1 << ANAT_FSE_TYPE)
 

Definition at line 1843 of file 3ddata.h.

#define ANAT_FSE_PREFIX   "fse"
 

Definition at line 1842 of file 3ddata.h.

#define ANAT_FSE_STR   "Fast Spin Echo"
 

Definition at line 1841 of file 3ddata.h.

#define ANAT_FSE_TYPE   1
 

Definition at line 1840 of file 3ddata.h.

#define ANAT_MAPC_MASK   (1 << ANAT_MAPC_TYPE)
 

Definition at line 1898 of file 3ddata.h.

#define ANAT_MAPC_PREFIX   "mapc"
 

Definition at line 1897 of file 3ddata.h.

#define ANAT_MAPC_STR   "Mapped Color"
 

Definition at line 1896 of file 3ddata.h.

#define ANAT_MAPC_TYPE   12
 

Definition at line 1895 of file 3ddata.h.

#define ANAT_MRA_MASK   (1 << ANAT_MRA_TYPE)
 

Definition at line 1873 of file 3ddata.h.

#define ANAT_MRA_PREFIX   "mra"
 

Definition at line 1872 of file 3ddata.h.

#define ANAT_MRA_STR   "MR Angiography"
 

Definition at line 1871 of file 3ddata.h.

#define ANAT_MRA_TYPE   7
 

Definition at line 1870 of file 3ddata.h.

#define ANAT_MRAN_MASK   (1 << ANAT_MRAN_TYPE)
 

Definition at line 1853 of file 3ddata.h.

#define ANAT_MRAN_PREFIX   "anat"
 

Definition at line 1852 of file 3ddata.h.

#define ANAT_MRAN_STR   "MRI Anatomy"
 

Definition at line 1851 of file 3ddata.h.

#define ANAT_MRAN_TYPE   3
 

Definition at line 1850 of file 3ddata.h.

Referenced by THD_open_analyze(), THD_open_ctfmri(), THD_open_minc(), and THD_open_mpeg().

#define ANAT_OMRI_MASK   (1 << ANAT_OMRI_TYPE)
 

Definition at line 1888 of file 3ddata.h.

#define ANAT_OMRI_PREFIX   "omri"
 

Definition at line 1887 of file 3ddata.h.

#define ANAT_OMRI_STR   "Other MRI"
 

Definition at line 1886 of file 3ddata.h.

#define ANAT_OMRI_TYPE   10
 

Definition at line 1885 of file 3ddata.h.

Referenced by DRAW_copy_dset().

#define ANAT_PET_MASK   (1 << ANAT_PET_TYPE)
 

Definition at line 1868 of file 3ddata.h.

#define ANAT_PET_PREFIX   "pet"
 

Definition at line 1867 of file 3ddata.h.

#define ANAT_PET_STR   "PET Anatomy"
 

Definition at line 1866 of file 3ddata.h.

#define ANAT_PET_TYPE   6
 

Definition at line 1865 of file 3ddata.h.

#define ANAT_SPECT_MASK   (1 << ANAT_SPECT_TYPE)
 

Definition at line 1863 of file 3ddata.h.

#define ANAT_SPECT_PREFIX   "spct"
 

Definition at line 1862 of file 3ddata.h.

#define ANAT_SPECT_STR   "SPECT Anatomy"
 

Definition at line 1861 of file 3ddata.h.

#define ANAT_SPECT_TYPE   5
 

Definition at line 1860 of file 3ddata.h.

#define ANAT_SPGR_MASK   (1 << ANAT_SPGR_TYPE)
 

Definition at line 1838 of file 3ddata.h.

Referenced by PLUGIN_init().

#define ANAT_SPGR_PREFIX   "spgr"
 

Definition at line 1837 of file 3ddata.h.

#define ANAT_SPGR_STR   "Spoiled GRASS"
 

Definition at line 1836 of file 3ddata.h.

#define ANAT_SPGR_TYPE   0
 

Definition at line 1835 of file 3ddata.h.

Referenced by EDIT_empty_copy(), and main().

#define ATLAS_AC_TO_LAT   68.0
 

Definition at line 679 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define ATLAS_AC_TO_PC   23.0
 

Definition at line 674 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define ATLAS_AC_TO_TOP   74.0
 

Definition at line 678 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define ATLAS_ALIGNBOX_ANT   95.0
 

Definition at line 690 of file 3ddata.h.

Referenced by AFNI_make_warp().

#define ATLAS_ALIGNBOX_INF   70.0
 

Definition at line 693 of file 3ddata.h.

Referenced by AFNI_make_warp().

#define ATLAS_ALIGNBOX_LAT   95.0
 

Definition at line 689 of file 3ddata.h.

Referenced by AFNI_make_warp().

#define ATLAS_ALIGNBOX_POS   140.0
 

Definition at line 691 of file 3ddata.h.

Referenced by AFNI_make_warp().

#define ATLAS_ALIGNBOX_SUP   100.0
 

Definition at line 692 of file 3ddata.h.

Referenced by AFNI_make_warp().

#define ATLAS_BBOX_ANT   80.0
 

Definition at line 682 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define ATLAS_BBOX_INF   55.0
 

Definition at line 684 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define ATLAS_BBOX_INF_NEW   65.0
 

Definition at line 687 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define ATLAS_BBOX_LAT   80.0
 

Definition at line 681 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define ATLAS_BBOX_POS   110.0
 

Definition at line 683 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define ATLAS_BBOX_SUP   85.0
 

Definition at line 685 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define ATLAS_BOT_TO_AC   42.0
 

Definition at line 677 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define ATLAS_FRONT_TO_AC   70.0
 

Atlas distances for acpc->tlrc markers. If you change these, change the helps below too

Definition at line 673 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define ATLAS_PC_TO_BACK   79.0
 

Definition at line 675 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define ATR_FLOAT_TYPE   1
 

Definition at line 427 of file 3ddata.h.

Referenced by atr_print(), main(), THD_anonymize_dset(), THD_copy_atr(), THD_erase_all_atr(), THD_erase_one_atr(), THD_find_atr(), THD_find_float_atr(), THD_insert_atr(), THD_nimlize_dsetatr(), THD_read_all_atr(), THD_set_atr(), THD_set_float_atr(), and THD_write_atr().

#define ATR_INT_TYPE   2
 

Definition at line 428 of file 3ddata.h.

Referenced by atr_print(), THD_anonymize_dset(), THD_copy_atr(), THD_erase_all_atr(), THD_erase_one_atr(), THD_find_atr(), THD_find_int_atr(), THD_insert_atr(), THD_nimlize_dsetatr(), THD_read_all_atr(), THD_set_atr(), THD_set_int_atr(), and THD_write_atr().

#define ATR_STRING_TYPE   0
 

Definition at line 426 of file 3ddata.h.

Referenced by atr_print(), main(), THD_anonymize_dset(), THD_copy_atr(), THD_erase_all_atr(), THD_erase_one_atr(), THD_find_atr(), THD_find_string_atr(), THD_insert_atr(), THD_nimlize_dsetatr(), THD_read_all_atr(), THD_set_atr(), THD_set_char_atr(), and THD_write_atr().

#define ATRNAME_ANATOMY_PARENT   "ANATOMY_PARENTNAME"
 

Definition at line 2939 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BRICK_FLTFAC   "BRICK_FLOAT_FACS"
 

Definition at line 3028 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BRICK_KEYWORDS   "BRICK_KEYWORDS"
 

Definition at line 3053 of file 3ddata.h.

Referenced by THD_anonymize_dset(), THD_datablock_apply_atr(), THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BRICK_LABS   "BRICK_LABS"
 

30 Nov 1997 *

Definition at line 3051 of file 3ddata.h.

Referenced by THD_datablock_apply_atr(), THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BRICK_STATAUX   "BRICK_STATAUX"
 

Definition at line 3052 of file 3ddata.h.

Referenced by THD_datablock_apply_atr(), THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BRICK_STATS   "BRICK_STATS"
 

Definition at line 3024 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BRICK_TYPES   "BRICK_TYPES"
 

additions 1995 Nov 15, for variable brick data types *

Definition at line 3020 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_BYTEORDER   "BYTEORDER_STRING"
 

Definition at line 951 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), THD_dataset_info(), and THD_write_datablock().

#define ATRNAME_DATANAME   "DATASET_NAME"
 

Definition at line 2935 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_anonymize_dset(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_DATASET_DIMENSIONS   "DATASET_DIMENSIONS"
 

Definition at line 3001 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_DATASET_RANK   "DATASET_RANK"
 

Definition at line 2997 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_DELTA   "DELTA"
 

Definition at line 2953 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_IDANATPAR   "IDCODE_ANAT_PARENT"
 

Definition at line 1498 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_IDDATE   "IDCODE_DATE"
 

Definition at line 1497 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_IDSTRING   "IDCODE_STRING"
 

Definition at line 1496 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), THD_dblkatr_from_niml(), and THD_set_dataset_attributes().

#define ATRNAME_IDWARPPAR   "IDCODE_WARP_PARENT"
 

Definition at line 1499 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_KEYWORDS   "DATASET_KEYWORDS"
 

Definition at line 3055 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_anonymize_dset(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_LABEL1   "LABEL_1"
 

Definition at line 2936 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_anonymize_dset(), and THD_set_dataset_attributes().

#define ATRNAME_LABEL2   "LABEL_2"
 

Definition at line 2937 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_anonymize_dset(), and THD_set_dataset_attributes().

#define ATRNAME_MARKSFLAG   "MARKS_FLAGS"
 

Definition at line 2973 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_MARKSHELP   "MARKS_HELP"
 

Definition at line 2969 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_MARKSLAB   "MARKS_LAB"
 

Definition at line 2965 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_MARKSXYZ   "MARKS_XYZ"
 

Definition at line 2961 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_MINMAX   "MINMAX"
 

Definition at line 3005 of file 3ddata.h.

Referenced by THD_3dim_from_block().

#define ATRNAME_ORIENT_GENERAL   "ORIENT_GENERAL" /*** not used yet ***/
 

Definition at line 2945 of file 3ddata.h.

#define ATRNAME_ORIENT_SPECIFIC   "ORIENT_SPECIFIC"
 

Definition at line 2941 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_ORIGIN   "ORIGIN"
 

Definition at line 2949 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_SCENE_TYPE   "SCENE_DATA"
 

Definition at line 2993 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_from_atr(), and THD_set_dataset_attributes().

#define ATRNAME_SKIP   "SKIP"
 

Definition at line 2957 of file 3ddata.h.

#define ATRNAME_STAT_AUX   "STAT_AUX"
 

1996 Mar 26 *

Definition at line 3034 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_TAXIS_FLOATS   "TAXIS_FLOATS"
 

Definition at line 3043 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_TAXIS_NUMS   "TAXIS_NUMS"
 

1996 May 14 *

Definition at line 3040 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_TAXIS_OFFSETS   "TAXIS_OFFSETS"
 

Definition at line 3046 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_TYPESTRING   "TYPESTRING"
 

Definition at line 2977 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_set_dataset_attributes().

#define ATRNAME_WARP_DATA   "WARP_DATA"
 

Definition at line 2985 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_WARP_PARENT   "WARP_PARENTNAME"
 

Definition at line 2989 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRNAME_WARP_TYPE   "WARP_TYPE"
 

Definition at line 2981 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define ATRSIZE_BRICK_FLTFAC   0
 

Definition at line 3030 of file 3ddata.h.

#define ATRSIZE_BRICK_STATS   0
 

Definition at line 3026 of file 3ddata.h.

#define ATRSIZE_BRICK_TYPES   0
 

Definition at line 3022 of file 3ddata.h.

#define ATRSIZE_DATASET_DIMENSIONS   THD_MAX_RANK_EVER
 

Definition at line 3003 of file 3ddata.h.

Referenced by THD_set_dataset_attributes(), and THD_write_datablock().

#define ATRSIZE_DATASET_RANK   8
 

Definition at line 2999 of file 3ddata.h.

Referenced by THD_set_dataset_attributes(), and THD_write_datablock().

#define ATRSIZE_DELTA   3
 

Definition at line 2955 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_MARKSFLAG   MARKS_MAXFLAG
 

Definition at line 2975 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_MARKSHELP   MARKS_HSIZE
 

Definition at line 2971 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_MARKSLAB   MARKS_LSIZE
 

Definition at line 2967 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_MARKSXYZ   MARKS_FSIZE
 

Definition at line 2963 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_ORIENT_GENERAL   9
 

Definition at line 2947 of file 3ddata.h.

#define ATRSIZE_ORIENT_SPECIFIC   3
 

Definition at line 2943 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_ORIGIN   3
 

Definition at line 2951 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_SCENE_TYPE   8
 

Definition at line 2995 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_SKIP   3
 

Definition at line 2959 of file 3ddata.h.

#define ATRSIZE_STAT_AUX   0
 

Definition at line 3036 of file 3ddata.h.

#define ATRSIZE_TAXIS_FLOATS   8
 

Definition at line 3044 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_TAXIS_NUMS   8
 

Definition at line 3041 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRSIZE_TAXIS_OFFSETS   0
 

Definition at line 3047 of file 3ddata.h.

#define ATRSIZE_TYPESTRING   0
 

Definition at line 2979 of file 3ddata.h.

#define ATRSIZE_WARP_DATA   0
 

Definition at line 2987 of file 3ddata.h.

#define ATRSIZE_WARP_PARENT   0
 

Definition at line 2991 of file 3ddata.h.

#define ATRSIZE_WARP_TYPE   8
 

Definition at line 2983 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define ATRTYPE_BRICK_FLTFAC   ATR_FLOAT_TYPE
 

Definition at line 3029 of file 3ddata.h.

#define ATRTYPE_BRICK_STATS   ATR_FLOAT_TYPE
 

Definition at line 3025 of file 3ddata.h.

#define ATRTYPE_BRICK_TYPES   ATR_INT_TYPE
 

Definition at line 3021 of file 3ddata.h.

#define ATRTYPE_DATASET_DIMENSIONS   ATR_INT_TYPE
 

Definition at line 3002 of file 3ddata.h.

#define ATRTYPE_DATASET_RANK   ATR_INT_TYPE
 

Definition at line 2998 of file 3ddata.h.

#define ATRTYPE_DELTA   ATR_FLOAT_TYPE
 

Definition at line 2954 of file 3ddata.h.

#define ATRTYPE_MARKSFLAG   ATR_INT_TYPE
 

Definition at line 2974 of file 3ddata.h.

#define ATRTYPE_MARKSHELP   ATR_STRING_TYPE
 

Definition at line 2970 of file 3ddata.h.

#define ATRTYPE_MARKSLAB   ATR_STRING_TYPE
 

Definition at line 2966 of file 3ddata.h.

#define ATRTYPE_MARKSXYZ   ATR_FLOAT_TYPE
 

Definition at line 2962 of file 3ddata.h.

#define ATRTYPE_MINMAX   ATR_INT_TYPE
 

Definition at line 3006 of file 3ddata.h.

#define ATRTYPE_ORIENT_GENERAL   ATR_FLOAT_TYPE
 

Definition at line 2946 of file 3ddata.h.

#define ATRTYPE_ORIENT_SPECIFIC   ATR_INT_TYPE
 

Definition at line 2942 of file 3ddata.h.

#define ATRTYPE_ORIGIN   ATR_FLOAT_TYPE
 

Definition at line 2950 of file 3ddata.h.

#define ATRTYPE_SCENE_TYPE   ATR_INT_TYPE
 

Definition at line 2994 of file 3ddata.h.

#define ATRTYPE_SKIP   ATR_FLOAT_TYPE
 

Definition at line 2958 of file 3ddata.h.

#define ATRTYPE_STAT_AUX   ATR_FLOAT_TYPE
 

Definition at line 3035 of file 3ddata.h.

#define ATRTYPE_TYPESTRING   ATR_STRING_TYPE
 

Definition at line 2978 of file 3ddata.h.

#define ATRTYPE_WARP_DATA   ATR_FLOAT_TYPE
 

Definition at line 2986 of file 3ddata.h.

#define ATRTYPE_WARP_PARENT   ATR_STRING_TYPE
 

Definition at line 2990 of file 3ddata.h.

#define ATRTYPE_WARP_TYPE   ATR_INT_TYPE
 

Definition at line 2982 of file 3ddata.h.

#define BADFIND ff   
 

Value:

( (ff).sess_index=(ff).dset_index=(ff).view_index=-1 , \
     (ff).dset = NULL )
Set the find codes to indicate a bad result

Definition at line 2924 of file 3ddata.h.

Referenced by PLUTO_dset_finder(), THD_dset_in_session(), and THD_dset_in_sessionlist().

#define BLANK_SESSION ss   
 

Value:

if( ISVALID_SESSION((ss)) ){                                                \
      int id , vv ;                                                           \
      for( id=0 ; id < THD_MAX_SESSION_SIZE ; id++ )                          \
        for( vv=0 ; vv <= LAST_VIEW_TYPE ; vv++ ) (ss)->dsset[id][vv] = NULL; \
      (ss)->num_dsset = 0 ;                                                   \
      (ss)->su_num    = 0 ; (ss)->su_surf = NULL ;                            \
      (ss)->su_numgroup = 0 ; (ss)->su_surfgroup = NULL ;                     \
      (ss)->warptable = NULL ; }
Initialize THD_session ss to hold nothing at all.

Definition at line 2866 of file 3ddata.h.

Referenced by AFNI_read_inputs(), and THD_init_session().

#define BLANK_SESSIONLIST sl   
 

Value:

if( ISVALID_SESSIONLIST((sl)) ){ \
      int is ; \
      for( is=0 ; is < THD_MAX_NUM_SESSION ; is++ ) (sl)->ssar[is] = NULL ; \
      (sl)->num_sess = 0 ; }
Initialize a THD_sessionlist to contain nothing.

Definition at line 2901 of file 3ddata.h.

Referenced by AFNI_read_inputs().

#define BRICK_DRAWABLE br       ((br)->n1 > 1 && (br)->n2 > 1)
 

Determine if this FD_brick can be drawn (in an image or graph)

Definition at line 3436 of file 3ddata.h.

Referenced by AFNI_underlay_CB().

#define BRICK_GRAPHABLE br       ((br)->n1 >= 1 && (br)->n2 >= 1)
 

Definition at line 3437 of file 3ddata.h.

Referenced by AFNI_underlay_CB().

#define CALC_HELP_STRING
 

Value:

"CALCULATED DATASETS\n"                                                 \
   "-------------------\n"                                                 \
   " Datasets may also be specified as runtime-generated results from\n"   \
   " program 3dcalc.  This type of dataset specifier is enclosed in\n"     \
   " quotes, and starts with the string '3dcalc(':\n"                      \
   "    '3dcalc( opt opt ... opt )'\n"                                     \
   " where each 'opt' is an option to program 3dcalc; this program\n"      \
   " is run to generate a dataset in the directory given by environment\n" \
   " variable TMPDIR (default=/tmp).  This dataset is then read into\n"    \
   " memory, locked in place, and deleted from disk.  For example\n"       \
   "    afni -dset '3dcalc( -a r1+orig -b r2+orig -expr 0.5*(a+b) )'\n"    \
   " will let you look at the average of datasets r1+orig and r2+orig.\n"  \
   " N.B.: using this dataset input method will use lots of memory!\n"
Help string to explain calculated datasets.

Definition at line 3235 of file 3ddata.h.

Referenced by AFNI_syntax().

#define CEN_WARP ww,
xin,
yin,
zin,
xout,
yout,
zout   
 

Value:

do{ THD_fvec3 tv , uv ;                                        \
      LOAD_FVEC3(tv,xin,yin,zin) ;                               \
      uv = MATVEC((ww).rig_bod.warp.mfor,tv) ;                   \
      LOAD_FVEC3(tv,xout,yout,zout) ;                            \
      (ww).rig_bod.warp.bvec = SUB_FVEC3(uv,tv) ;                \
      (ww).rig_bod.warp.svec =                                   \
         MATVEC((ww).rig_bod.warp.mbac,(ww).rig_bod.warp.bvec) ; \
      NEGATE_FVEC3((ww).rig_bod.warp.svec) ;                     \
  } while(0)
Make the affine warp map point (xin,yin,zin) to (xout,yout,zout).

Definition at line 876 of file 3ddata.h.

#define COPY_FROM_STRUCT str,
off,
type,
ptr,
n       (void) memcpy( (char *)(ptr), (char *)(&(str))+(off), (n)*sizeof(type) )
 

Copy n units of the given type "type * ptr", from a structure "str", starting at byte offset "off"; N.B.: str is the structure itself, not a pointer to it off is most easily computed with XtOffsetOf

Definition at line 188 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define COPY_INTO_STRUCT str,
off,
type,
ptr,
n       (void) memcpy( (char *)(&(str))+(off), (char *)(ptr), (n)*sizeof(type) )
 

Copy n units of the given type "type * ptr", into a structure "str", starting at byte offset "off"; N.B.: str is the structure itself, not a pointer to it off is most easily computed with XtOffsetOf

Definition at line 180 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define COPY_LMAP_BOUNDS m1,
m2       ( (m1).bot=(m2).bot , (m1).top=(m2).top )
 

Copy the .bot and .top bounds between two THD_linear_mapping structs.

Definition at line 508 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), and AFNI_follower_dataset().

#define CURRENT_DAXES ds       (((ds)->wod_flag) ? ((ds)->wod_daxes) : ((ds)->daxes))
 

Return pointer to current dataset axes (warp-on-demand or permanent).

Definition at line 2048 of file 3ddata.h.

Referenced by AFNI_brick_to_mri(), AFNI_dataset_slice(), AFNI_do_many_writes(), AFNI_jumpto_dicom(), AFNI_jumpto_ijk(), AFNI_lock_carryout(), AFNI_make_voxwarp(), AFNI_seq_send_CB(), AFNI_set_viewpoint(), AFNI_slice_flip(), AFNI_talto_CB(), AFNI_write_dataset_CB(), brainnormalize_coord(), THD_3dfind_to_3dmm(), THD_3dim_dataset_to_brick(), THD_3dind_to_3dmm(), THD_3dmm_to_3dfind(), THD_3dmm_to_3dind(), THD_oriented_brick(), and THD_setup_bricks().

#define DATABLOCK_MEM_ANY   (DATABLOCK_MEM_MALLOC | DATABLOCK_MEM_MMAP)
 

Definition at line 1005 of file 3ddata.h.

Referenced by PLUTO_add_dset(), RT_tell_afni_one(), and THD_force_malloc_type().

#define DATABLOCK_MEM_MALLOC   2
 

Definition at line 1003 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_fimmer_compute(), AFNI_misc_CB(), AFNI_read_images(), AFNI_read_inputs(), AFNI_refashion_dataset(), B2F_read_opts(), basis_write_iresp(), basis_write_sresp(), BUCK_read_opts(), do_xrestore_stuff(), EDIT_add_bricklist(), EDIT_empty_copy(), EDIT_one_dataset(), EDIT_substitute_brick(), fim3d_fimmer_compute(), form_clusters(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), output_ts_array(), PERMTEST_main(), POWER_main(), r_fill_resampled_data_brick(), REORDER_main(), RT_fim_recurse(), RT_start_dataset(), STAVG_main(), SUMA_BrainVoyager_Read_vmr(), SUMA_OpenDX_Read_CruiseVolHead(), T3D_read_images(), TCAT_read_opts(), THD_alloc_datablock(), THD_copy_dset_subs(), THD_datablock_from_atr(), THD_delete_datablock(), THD_force_malloc_type(), THD_load_1D(), THD_load_3D(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_datablock(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), THD_open_1D(), THD_open_3D(), THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), THD_purge_datablock(), THD_purge_one_brick(), THD_setup_mastery(), THD_warp3D(), THD_write_datablock(), THRESH_main(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), write_ts_array(), and ZCAT_read_opts().

#define DATABLOCK_MEM_MMAP   4
 

Definition at line 1004 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_misc_CB(), AFNI_refashion_dataset(), THD_datablock_from_atr(), THD_delete_datablock(), THD_force_malloc_type(), THD_load_datablock(), THD_purge_datablock(), and THD_write_datablock().

#define DATABLOCK_MEM_SHARED   8
 

Definition at line 1006 of file 3ddata.h.

Referenced by AFNI_misc_CB(), THD_alloc_datablock(), THD_delete_datablock(), THD_load_datablock(), and THD_purge_datablock().

#define DATABLOCK_MEM_UNDEFINED   1
 

Definition at line 1002 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), adwarp_refashion_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_refashion_dataset(), duplicate_dataset(), EDIT_empty_datablock(), EDIT_wod_copy(), THD_init_one_datablock(), THD_load_datablock(), and THD_write_datablock().

#define DATABLOCK_TYPE   37
 

Definition at line 1000 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), duplicate_dataset(), EDIT_empty_copy(), EDIT_empty_datablock(), T3D_read_images(), and THD_init_one_datablock().

#define DATASET_BRICK_SUFFIX   "BRIK"
 

Definition at line 899 of file 3ddata.h.

Referenced by main(), T3D_create_widgets(), THD_init_diskptr_names(), THD_open_one_dataset(), THD_rename_dataset_files(), and THD_write_datablock().

#define DATASET_HEADER_SUFFIX   "HEAD"
 

Definition at line 898 of file 3ddata.h.

Referenced by T3D_check_data(), T3D_create_widgets(), THD_init_alldir_datablocks(), THD_init_diskptr_names(), THD_init_one_datablock(), THD_init_prefix_datablocks(), THD_open_one_dataset(), and THD_rename_dataset_files().

#define DATASET_NOTES_SUFFIX   "NOTE"
 

Definition at line 900 of file 3ddata.h.

#define DATAXES_TO_DISKPTR ds   
 

Value:

( (ds)->dblk->diskptr->dimsizes[0] = (ds)->daxes->nxx ,  \
    (ds)->dblk->diskptr->dimsizes[1] = (ds)->daxes->nyy ,  \
    (ds)->dblk->diskptr->dimsizes[2] = (ds)->daxes->nzz  )
WARNING: If you perform surgery on a dataset and change its dimensions in the dataxes, you must also reflect this in the diskptr. Otherwise, the .HEAD file will not have the correct dimensions! The macro just below will do this for you.

Definition at line 1319 of file 3ddata.h.

#define DATAXES_TYPE   27
 

Definition at line 1194 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_do_many_writes(), AFNI_init_warp(), AFNI_make_wid2(), AFNI_read_images(), AFNI_refashion_dataset(), AFNI_write_dataset_CB(), EDIT_empty_copy(), main(), r_new_resam_dset(), T3D_read_images(), and THD_3dim_from_block().

#define DAXES_NUM dax,
ori   
 

Value:

( (ORIENT_xyzint[(ori)] == ORIENT_xyzint[(dax)->xxorient]) ? (dax)->nxx : \
     (ORIENT_xyzint[(ori)] == ORIENT_xyzint[(dax)->yyorient]) ? (dax)->nyy : \
     (ORIENT_xyzint[(ori)] == ORIENT_xyzint[(dax)->zzorient]) ? (dax)->nzz : 0 )

Definition at line 1302 of file 3ddata.h.

Referenced by main(), and THD_dataset_info().

#define DAXES_XCEN dax       ((dax)->xxorg + 0.5*((dax)->nxx - 1) * (dax)->xxdel)
 

Center of grid in x-direction.

Definition at line 1293 of file 3ddata.h.

#define DAXES_YCEN dax       ((dax)->yyorg + 0.5*((dax)->nyy - 1) * (dax)->yydel)
 

Center of grid in y-direction.

Definition at line 1296 of file 3ddata.h.

#define DAXES_ZCEN dax       ((dax)->zzorg + 0.5*((dax)->nzz - 1) * (dax)->zzdel)
 

Center of grid in z-direction.

Definition at line 1299 of file 3ddata.h.

#define DBLK_anyize db       THD_force_malloc_type((db),DATABLOCK_MEM_ANY)
 

Don't care how bricks are allocated.

Definition at line 1084 of file 3ddata.h.

#define DBLK_ARRAY db,
iv       mri_data_pointer( DBLK_BRICK((db),(iv)) )
 

Definition at line 2254 of file 3ddata.h.

Referenced by ENTROPY_datablock(), THD_alloc_datablock(), THD_count_databricks(), THD_fetch_dataset(), THD_load_1D(), THD_load_3D(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_datablock(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), THD_purge_datablock(), THD_purge_one_brick(), and THD_write_datablock().

#define DBLK_BRICK db,
iv       ((db)->brick->imarr[(iv)])
 

Definition at line 2238 of file 3ddata.h.

Referenced by T3D_fix_dataset_dimen(), T3D_read_images(), THD_alloc_datablock(), THD_count_databricks(), THD_fetch_dataset(), THD_load_1D(), THD_load_3D(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_datablock(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), THD_purge_datablock(), THD_purge_one_brick(), and THD_write_datablock().

#define DBLK_BRICK_ARRAY   DBLK_ARRAY
 

Definition at line 2261 of file 3ddata.h.

#define DBLK_BRICK_BYTES db,
iv       ((db)->brick_bytes[iv])
 

Definition at line 2277 of file 3ddata.h.

Referenced by ENTROPY_datablock(), THD_alloc_datablock(), THD_fetch_dataset(), THD_load_1D(), THD_load_3D(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_datablock(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), and THD_write_datablock().

#define DBLK_BRICK_FACTOR db,
iv       ((db)->brick_fac[(iv)])
 

Definition at line 2263 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), main(), r_fill_resampled_data_brick(), and THD_load_datablock().

#define DBLK_BRICK_KEYWORDS db,
iv       ( ((db)->brick_keywords != NULL) ? ((db)->brick_keywords[iv]) : NULL )
 

Definition at line 2562 of file 3ddata.h.

#define DBLK_BRICK_LAB db,
iv       ( ((db)->brick_lab != NULL) ? ((db)->brick_lab[iv]) : "?" )
 

Definition at line 2514 of file 3ddata.h.

#define DBLK_BRICK_NVOX db,
iv       (DBLK_BRICK((db),(iv))->nvox)
 

Return the number of voxels in the iv-th volume of dataset ds

Definition at line 2252 of file 3ddata.h.

Referenced by THD_fetch_dataset(), THD_load_analyze(), THD_load_ctfmri(), THD_load_datablock(), THD_load_nifti(), and THD_write_datablock().

#define DBLK_BRICK_STATAUX db,
iv       ( ((db)->brick_stataux != NULL) ? (db)->brick_stataux[iv] : NULL )
 

Definition at line 2538 of file 3ddata.h.

#define DBLK_BRICK_STATCODE db,
iv       ( ((db)->brick_statcode != NULL) ? (db)->brick_statcode[iv] : ILLEGAL_TYPE )
 

Definition at line 2526 of file 3ddata.h.

#define DBLK_BRICK_STATPAR db,
iv,
jj       ( ((db)->brick_stataux != NULL) ? (db)->brick_stataux[iv][jj] : 0.0 )
 

Definition at line 2552 of file 3ddata.h.

#define DBLK_BRICK_TYPE db,
iv       (DBLK_BRICK((db),(iv))->kind)
 

Definition at line 2244 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), T3D_save_file_CB(), THD_datablock_from_atr(), THD_datum_constant(), THD_fetch_dataset(), THD_init_datablock_brick(), THD_load_analyze(), THD_load_ctfmri(), THD_load_datablock(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), THD_set_dataset_attributes(), THD_setup_mastery(), and THD_write_datablock().

#define DBLK_BYTEORDER db       ((db)->diskptr->byte_order)
 

Definition at line 2344 of file 3ddata.h.

#define DBLK_IS_1D db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) &&     \
                         (db)->diskptr->storage_mode == STORAGE_BY_1D )
Determine if datablock db is stored in a 1D file on disk

Definition at line 2153 of file 3ddata.h.

#define DBLK_IS_3D db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) &&     \
                         (db)->diskptr->storage_mode == STORAGE_BY_3D )
Determine if datablock db is stored in a 3D file on disk

Definition at line 2158 of file 3ddata.h.

#define DBLK_IS_ANALYZE db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) && \
                              (db)->diskptr->storage_mode == STORAGE_BY_ANALYZE )
Determine if datablock db is stored in a ANALYZE file on disk

Definition at line 2120 of file 3ddata.h.

Referenced by THD_write_atr(), and THD_write_datablock().

#define DBLK_IS_CTFMRI db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) && \
                             (db)->diskptr->storage_mode == STORAGE_BY_CTFMRI )
Determine if datablock db is stored in a CTFMRI file on disk

Definition at line 2131 of file 3ddata.h.

Referenced by THD_write_atr().

#define DBLK_IS_CTFSAM db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) && \
                             (db)->diskptr->storage_mode == STORAGE_BY_CTFSAM )
Determine if datablock db is stored in a CTFSAM file on disk

Definition at line 2142 of file 3ddata.h.

Referenced by THD_write_atr().

#define DBLK_IS_MALLOC db       ((db)->malloc_type == DATABLOCK_MEM_MALLOC)
 

Test if brick is set to be malloc()-ed.

Definition at line 1088 of file 3ddata.h.

#define DBLK_IS_MASTERED db       ((db)->master_nvals > 0 && (db)->master_ival != NULL && (db)->master_bytes != NULL)
 

Check if brick is mastered from another dataset.

Definition at line 1119 of file 3ddata.h.

Referenced by THD_delete_datablock(), THD_load_datablock(), and THD_write_datablock().

#define DBLK_IS_MINC db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) && \
                           (db)->diskptr->storage_mode == STORAGE_BY_MINC )
Determine if datablock db is stored in a MINC file on disk

Definition at line 2109 of file 3ddata.h.

Referenced by THD_write_atr(), and THD_write_datablock().

#define DBLK_IS_MMAP db       ((db)->malloc_type == DATABLOCK_MEM_MMAP)
 

Test if brick is set to be mmap()-ed.

Definition at line 1092 of file 3ddata.h.

#define DBLK_IS_MPEG db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) && \
                           (db)->diskptr->storage_mode == STORAGE_BY_MPEG )
Determine if datablock db is stored in a MPEG file on disk

Definition at line 2199 of file 3ddata.h.

Referenced by THD_write_atr().

#define DBLK_IS_NIFTI db   
 

Value:

( ISVALID_DBLK(db) && ISVALID_DISKPTR((db)->diskptr) &&  \
                           (db)->diskptr->storage_mode == STORAGE_BY_NIFTI )
Determine if datablock db is stored in a NIFTI file on disk

Definition at line 2163 of file 3ddata.h.

Referenced by THD_write_atr(), and THD_write_datablock().

#define DBLK_IS_SHARED db       ((db)->malloc_type == DATABLOCK_MEM_SHARED)
 

Test if brick is set to be shared.

Definition at line 1096 of file 3ddata.h.

#define DBLK_IS_VOLUMES db   
 

Value:

( ISVALID_DBLK(db) &&                                \
                              ISVALID_DISKPTR((db)->diskptr) &&                  \
                              (db)->diskptr->storage_mode == STORAGE_BY_VOLUMES )
Determine if datablock db is stored by volume files rather than 1 big BRIK

Definition at line 2186 of file 3ddata.h.

#define DBLK_lock db       ((db)->locked = 1)
 

Lock bricks in memory.

Definition at line 1104 of file 3ddata.h.

#define DBLK_LOCKED db       ((db)->locked)
 

Test if brick is locked into memory.

Definition at line 1112 of file 3ddata.h.

Referenced by AFNI_misc_CB(), THD_force_malloc_type(), THD_purge_datablock(), and THD_purge_one_brick().

#define DBLK_mallocize db       THD_force_malloc_type((db),DATABLOCK_MEM_MALLOC)
 

Force bricks to be allocated with malloc().

Definition at line 1076 of file 3ddata.h.

#define DBLK_mmapfix db   
 

Value:

do{ if( (db)->malloc_type==DATABLOCK_MEM_MMAP && (db)->total_bytes>TWOGIG ) \
        (db)->malloc_type = DATABLOCK_MEM_MALLOC ; } while(0)

Definition at line 2750 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), THD_datablock_from_atr(), THD_force_malloc_type(), THD_load_datablock(), and THD_write_datablock().

#define DBLK_mmapize db       THD_force_malloc_type((db),DATABLOCK_MEM_MMAP)
 

Force bricks to be allocated with mmap().

Definition at line 1080 of file 3ddata.h.

#define DBLK_shareize db       THD_force_malloc_type((db),DATABLOCK_MEM_SHARED)
 

Force bricks to be allocated in shared memory.

Definition at line 1100 of file 3ddata.h.

#define DBLK_superlock db       ((db)->locked = 2)
 

Superlock brick in memory. Can only be undone by explicit access to db->locked.

Definition at line 1115 of file 3ddata.h.

#define DBLK_unlock db       ((db)->locked = ((db)->locked<2) ? 0 : 2)
 

Unlock bricks from memory, if they aren't "superlocked".

Definition at line 1108 of file 3ddata.h.

Referenced by duplicate_dataset(), EDIT_empty_copy(), EDIT_empty_datablock(), and THD_init_one_datablock().

#define DEFAULT_RESAMPLE_VOX   1.0
 

Default resampling grid size (in mm).

Definition at line 1198 of file 3ddata.h.

#define DELTA_AFTER   1
 

Definition at line 3540 of file 3ddata.h.

Referenced by main(), NUD_rotate(), parset_affine(), and rotate_stdin_points().

#define DELTA_BEFORE   2
 

Definition at line 3541 of file 3ddata.h.

Referenced by main(), parset_affine(), rot_to_shear(), and rotate_stdin_points().

#define DELTA_FIXED   3
 

Definition at line 3542 of file 3ddata.h.

Referenced by main(), and rot_to_shear().

#define DESTROY_SARR name   
 

Value:

do{ if( (name) != NULL ){    \
     KILL_KILL((name)->kl) ;  \
     myXtFree( (name)->ar ) ; \
     myXtFree( (name) ) ; } } while(0)
Kill all entries in the dynamic string array "name".

Definition at line 328 of file 3ddata.h.

Referenced by AFNI_read_inputs(), AFNI_rescan_timeseries_CB(), ISQ_saver_CB(), NLFIT_get_all_MODELs(), NLFIT_get_many_MODELs(), PLUG_get_all_plugins(), PLUG_get_many_plugins(), THD_extract_directories(), THD_extract_regular_files(), THD_get_all_executables(), THD_get_all_subdirs(), THD_get_all_timeseries(), THD_get_many_timeseries(), THD_getpathprogs(), THD_init_alldir_datablocks(), THD_normalize_flist(), and TT_whereami().

#define DESTROY_XTARR   FREE_XTARR
 

Duplicate definition for FREE_XTARR

Definition at line 271 of file 3ddata.h.

Referenced by AFNI_add_interruptable().

#define DETREND_const n,
     THD_const_detrend(n,f,NULL)
 

Definition at line 3472 of file 3ddata.h.

#define DETREND_cubic n,
     THD_cubic_detrend(n,f)
 

Definition at line 3471 of file 3ddata.h.

#define DETREND_linear n,
     THD_linear_detrend(n,f,NULL,NULL)
 

Definition at line 3469 of file 3ddata.h.

#define DETREND_polort p,
n,
 
 

Value:

do{ switch(p){ default:                         break;  \
                 case 0: DETREND_const(n,f)    ; break;  \
                 case 1: DETREND_linear(n,f)   ; break;  \
                 case 2: DETREND_quadratic(n,f); break;  \
                 case 3: DETREND_cubic(n,f)    ; break; } } while(0)
Macro to detrend a time series array in to various polynomial orders.

Definition at line 3476 of file 3ddata.h.

Referenced by main().

#define DETREND_quadratic n,
     THD_quadratic_detrend(n,f,NULL,NULL,NULL)
 

Definition at line 3470 of file 3ddata.h.

#define DISKPTR_TYPE   47
 

Definition at line 890 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), duplicate_dataset(), EDIT_empty_copy(), EDIT_empty_datablock(), r_idisp_thd_diskptr(), T3D_read_images(), and THD_init_one_datablock().

#define DOOMED   665
 

A marker that defines a dataset that is about to be killed.

Definition at line 2025 of file 3ddata.h.

Referenced by AFNI_andersonville(), and AFNI_mark_for_death().

#define DSET_anyize ds       DBLK_anyize((ds)->dblk)
 

Let AFNI decide how to load a dataset into memory.

May choose mmap() or malloc()

Definition at line 2720 of file 3ddata.h.

Referenced by DRAW_done_CB(), DRAW_quit_CB(), DRAW_saveas_finalize_CB(), NUD_finalize_dset_CB(), NUD_quit_CB(), and r_save_dataset_as().

#define DSET_ARRAY ds,
iv       DBLK_ARRAY((ds)->dblk,(iv))
 

Return the pointer to the actual data in the iv-th volume of dataset ds

Definition at line 2258 of file 3ddata.h.

Referenced by AFNI_dataset_slice(), AFNI_fimmer_compute(), AFNI_misc_CB(), applyMask(), BFIT_main(), BFIT_prepare_dataset(), CALC_read_opts(), CORREL_main(), DRAW_ttatlas_CB(), DSET_cor(), dset_to_mri(), edgeDetect(), EDIT_main(), EDIT_one_dataset(), eval_registration(), FD_brick_to_mri(), FD_brick_to_series(), fill_afni_struct(), fim3d_fimmer_compute(), Fourier_Filter_Driver(), get_options(), HISTO_main(), IMREG_main(), load_histo(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), MASKAVE_main(), PC_read_opts(), PERMTEST_compute(), PLUTO_4D_to_nothing(), POWER_main(), process_as_floats(), process_data(), r_set_afni_s_from_dset(), RCREND_overlay_ttatlas(), RCREND_reload_dataset(), RCREND_reload_func_dset(), remove_isolated_stuff(), REND_overlay_ttatlas(), REND_reload_dataset(), REND_reload_func_dset(), REORDER_main(), ROIPLOT_main(), RT_fim_recurse(), SCAT_main(), SUMA_Get_isosurface_datasets(), SUMA_LoadPrepInVol(), SUMA_SurfGridIntersect(), THD_add_bricks(), THD_autonudge(), THD_copy_dset_subs(), THD_extract_array(), THD_extract_float_brick(), THD_extract_many_series(), THD_get_dset_row(), THD_get_voxel(), THD_insert_series(), THD_load_tcat(), THD_makemask(), thd_mask_from_brick(), THD_put_dset_row(), THD_subbrick_to_niml(), THD_write_1D(), THD_write_minc(), THD_write_nifti(), THD_zerofill_dataset(), THRESH_compute(), and UC_read_opts().

#define DSET_BRICK ds,
iv       DBLK_BRICK((ds)->dblk,(iv))
 

Return the MRI_IMAGE * that is the iv-th volume of dataset ds

Definition at line 2242 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), AFNI_read_images(), AFNI_vnlist_func_overlay(), AFNI_vol2surf_func_overlay(), DRAW_fillin_CB(), EDIT_main(), EDIT_substitute_brick(), fim3d_fimmer_compute(), main(), NUD_doall_CB(), NUD_nudge_CB(), output_ts_array(), PERMTEST_main(), RCREND_reload_dataset(), RCREND_reload_func_dset(), REND_reload_dataset(), REND_reload_func_dset(), RT_fim_recurse(), RT_registration_3D_onevol(), RT_registration_3D_setup(), THD_cmass(), THD_extract_float_brick(), THD_load_statistics(), THD_load_tcat(), THD_mean_brick(), THD_median_brick(), THD_rms_brick(), THD_update_one_bstat(), THD_update_statistics(), THD_warp3D(), THD_zerofill_dataset(), THD_zeropad(), THRESH_main(), VL_command_line(), VOLREG_main(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), and write_ts_array().

#define DSET_BRICK_ARRAY   DSET_ARRAY
 

Definition at line 2260 of file 3ddata.h.

Referenced by center_of_mass(), copy_dset(), COPY_main(), DRAW_copy_dset(), DRAW_into_dataset(), DRAW_receiver(), EDIT_full_copy(), estpdf_initialize(), initialize_program(), main(), process_NIML_Node_ROI(), r_init_afni_vars(), r_init_Alg_values(), remove_field(), resample(), RT_registration_2D_onevol(), RT_registration_2D_setup(), segment_x_slices(), segment_y_slices(), segment_z_slices(), SUMA_FormAfnidset(), target_into_dataset(), TT_whereami(), and WINsorize().

#define DSET_BRICK_BYTES ds,
iv       DBLK_BRICK_BYTES((ds)->dblk,(iv))
 

Return number of bytes stored in the iv-th volume of dataset ds

Definition at line 2281 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), AFNI_read_inputs(), CALC_read_opts(), copy_dset(), COPY_main(), DRAW_copy_dset(), EDIT_full_copy(), fim3d_fimmer_compute(), main(), RT_fim_recurse(), THD_write_nifti(), and THD_zerofill_dataset().

#define DSET_BRICK_FACTOR ds,
iv       DBLK_BRICK_FACTOR((ds)->dblk,(iv))
 

Return the brick scaling factor of the iv-th volume of dataset ds.

If the scale factor is 0, then the brick is used "as-is"; that is, the effective scale factor is 1. You can assign to this macro as in "DSET_BRICK_FACTOR(ds,iv)=3.2;" but I don't recommend this. Instead, do something like "EDIT_BRICK_FACTOR(ds,iv,3.2);" (see editvol.h).

Definition at line 2273 of file 3ddata.h.

Referenced by AFNI_dataset_slice(), AFNI_fimmer_compute(), AFNI_func_overlay(), AFNI_vnlist_func_overlay(), avg_epochs(), BFIT_prepare_dataset(), CALC_read_opts(), calculate_results(), CORREL_main(), DRAW_finalize_dset_CB(), DRAW_into_dataset(), DRAW_receiver(), DRAW_saveas_finalize_CB(), EDIT_main(), EDIT_one_dataset(), FD_brick_to_mri(), fill_afni_struct(), Fourier_Filter_Driver(), HISTO_main(), initialize_program(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), MASKAVE_main(), openDataset(), PERMTEST_compute(), PLUTO_4D_to_nothing(), populate_nifti_image(), POWER_main(), process_all_datasets(), process_as_floats(), process_data(), process_subbrick(), r_init_afni_vars(), r_set_afni_s_from_dset(), RCREND_choose_av_CB(), RCREND_finalize_dset_CB(), RCREND_finalize_func_CB(), RCREND_reload_dataset(), RCREND_reload_func_dset(), read_afni_data(), REND_choose_av_CB(), REND_finalize_dset_CB(), REND_finalize_func_CB(), REND_reload_dataset(), REND_reload_func_dset(), RIC_CalcCoeffAB(), RIC_CalcVoxelMeans(), RIC_CorrectDataset(), ROIPLOT_main(), s2v_nodes2volume(), SCAT_main(), SUMA_Get_isosurface_datasets(), SUMA_LoadPrepInVol(), SUMA_SurfGridIntersect(), THD_autonudge(), THD_dataset_info(), THD_extract_array(), THD_extract_float_brick(), THD_get_voxel(), THD_load_statistics(), THD_load_tcat(), THD_makemask(), thd_mask_from_brick(), THD_mean_brick(), THD_median_brick(), THD_need_brick_factor(), THD_rms_brick(), THD_subbrick_to_niml(), THD_update_one_bstat(), THD_update_statistics(), THD_warp3D(), THD_write_1D(), and THD_write_minc().

#define DSET_BRICK_KEYWORDS ds,
iv       DBLK_BRICK_KEYWORDS((ds)->dblk,(iv))
 

Definition at line 2565 of file 3ddata.h.

Referenced by main(), and THD_dataset_info().

#define DSET_BRICK_KEYWORDS_HAS ds,
iv,
ss       THD_string_has( DSET_BRICK_KEYWORDS((ds),(iv)) , (ss) )
 

Definition at line 2569 of file 3ddata.h.

#define DSET_BRICK_LAB ds,
iv       DBLK_BRICK_LAB((ds)->dblk,(iv))
 

Return the label string for sub-brick iv of dataset ds.

This label is used on chooser menus, for example

Definition at line 2520 of file 3ddata.h.

Referenced by AFNI_bucket_label_CB(), and THD_dataset_info().

#define DSET_BRICK_LABEL   DSET_BRICK_LAB
 

Synonym for DSET_BRICK_LAB

Definition at line 2524 of file 3ddata.h.

Referenced by AFNI_bucket_label_CB(), AFNI_setup_viewing(), main(), MASKAVE_main(), NUD_brick_av_label_CB(), process_subbrick(), RCREND_choose_av_label_CB(), and REND_choose_av_label_CB().

#define DSET_BRICK_STATAUX ds,
iv   
 

Value:

( ISBUCKET((ds)) ? DBLK_BRICK_STATAUX((ds)->dblk,(iv))                  \
                    : (ISFUNC(ds) && (iv)==FUNC_ival_thr[(ds)->func_type]) \
                      ? (ds)->stat_aux : NULL )
Return float * pointer to statistical parameters for sub-brick iv in dataset ds.

If return is NULL, there aren't any parameters for this sub-brick, otherwise the number of parameters is given by FUNC_need_stat_aux[code], where code = DSET_BRICK_STATCODE(ds,iv).

Definition at line 2547 of file 3ddata.h.

Referenced by AFNI_drive_set_threshnew(), AFNI_set_thr_pval(), AFNI_thrdrag_lock_carryout(), AFNI_thresh_lock_carryout(), EDIT_one_dataset(), main(), process_subbrick(), RCREND_set_thr_pval(), and REND_set_thr_pval().

#define DSET_BRICK_STATCODE ds,
iv   
 

Value:

( ISBUCKET((ds)) ? DBLK_BRICK_STATCODE((ds)->dblk,(iv))                 \
                    : (ISFUNC(ds) && (iv)==FUNC_ival_thr[(ds)->func_type]) \
                      ? (ds)->func_type : -1 )
Return the statistical type code for the iv-th volume of dataset ds.

Will be -1 if this sub-brick is not tagged as being an SPM.

Definition at line 2533 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_drive_set_threshnew(), AFNI_refashion_dataset(), AFNI_set_thr_pval(), AFNI_setup_viewing(), AFNI_thr_scale_drag_CB(), AFNI_thrdrag_lock_carryout(), AFNI_thresh_lock_carryout(), EDIT_one_dataset(), FD_warp_to_mri(), main(), populate_nifti_image(), process_dataset(), process_subbrick(), RCREND_set_thr_pval(), REND_set_thr_pval(), THD_dataset_info(), and THD_write_1D().

#define DSET_BRICK_STATPAR ds,
iv,
jj   
 

Value:

( ISBUCKET((ds)) ? DBLK_BRICK_STATPAR((ds)->dblk,(iv),(jj))             \
                    : (ISFUNC(ds) && (iv)==FUNC_ival_thr[(ds)->func_type]) \
                      ? (ds)->stat_aux[jj] : 0.0 )
Return the jj-th statistical parameter for the iv-th volume of dataset ds.

Definition at line 2557 of file 3ddata.h.

Referenced by main(), populate_nifti_image(), THD_dataset_info(), and THD_write_1D().

#define DSET_BRICK_TYPE ds,
iv       DBLK_BRICK_TYPE((ds)->dblk,(iv))
 

Return the datum code (MRI_short, etc.) of the iv-th volume of dataset ds

Definition at line 2248 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_dataset_slice(), AFNI_fimmer_compute(), AFNI_refashion_dataset(), applyMask(), avg_epochs(), BFIT_prepare_dataset(), CALC_read_opts(), copy_dset(), COPY_main(), CORREL_main(), DRAW_copy_dset(), DRAW_into_dataset(), DRAW_receiver(), DSET_cor(), dset_to_mri(), edgeDetect(), EDIT_dset_items(), EDIT_full_copy(), EDIT_main(), EDIT_one_dataset(), eval_registration(), FD_brick_to_mri(), FD_brick_to_series(), fim3d_fimmer_compute(), Fourier_Filter_Driver(), get_options(), HISTO_main(), IMREG_main(), initialize_program(), load_histo(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), MASKAVE_main(), MRG_read_opts(), NUD_choose_CB(), openDataset(), PC_read_opts(), PERMTEST_compute(), PERMTEST_main(), PLUGIN_dset_check(), PLUTO_4D_to_nothing(), populate_nifti_image(), POWER_main(), process_all_datasets(), process_subbrick(), r_fill_resampled_data_brick(), r_init_afni_vars(), RCREND_reload_dataset(), read_afni_data(), REND_reload_dataset(), REORDER_main(), RIC_CalcCoeffAB(), RIC_CalcVoxelMeans(), RIC_CorrectDataset(), ROIPLOT_main(), RT_fim_recurse(), RT_registration_2D_onevol(), RT_registration_2D_setup(), SCAT_main(), set_smap_opts(), STAVG_main(), SUMA_Get_isosurface_datasets(), SUMA_LoadPrepInVol(), SUMA_SurfGridIntersect(), THD_autonudge(), THD_copy_dset_subs(), THD_dataset_info(), THD_dataset_rowfillin(), THD_dataset_zfillin(), THD_extract_array(), THD_extract_float_brick(), THD_extract_many_series(), THD_extract_series(), THD_get_dset_row(), THD_get_voxel(), THD_insert_series(), THD_load_tcat(), THD_makemask(), thd_mask_from_brick(), THD_put_dset_row(), THD_subbrick_to_niml(), THD_write_1D(), THD_write_minc(), THRESH_main(), UC_read_opts(), validate_datasets(), verify_inputs(), WINsorize(), write_afni_data(), and ZCAT_read_opts().

#define DSET_BRICKNAME   DSET_BRIKNAME
 

Definition at line 2325 of file 3ddata.h.

Referenced by main().

#define DSET_BRIKNAME ds   
 

Value:

(((ds)->dblk!=NULL && (ds)->dblk->diskptr!=NULL) \
                         ? ((ds)->dblk->diskptr->brick_name) : "\0" )
Return a pointer to the .BRIK filename of dataset ds

Definition at line 2323 of file 3ddata.h.

Referenced by basis_write_iresp(), basis_write_sresp(), EDIT_main(), EDIT_one_dataset(), main(), output_results(), output_ts_array(), THD_dataset_info(), THD_load_datablock(), THD_write_1D(), VL_command_line(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), and write_ts_array().

#define DSET_BYTEORDER ds       DBLK_BYTEORDER((ds)->dblk)
 

Return LSB_FIRST or MSB_FIRST for dataset ds

Definition at line 2348 of file 3ddata.h.

Referenced by main(), and THD_dataset_info().

#define DSET_COMPRESSED ds   
 

Value:

( ISVALID_DSET(ds) && (ds)->dblk!=NULL && \
     (ds)->dblk->diskptr != NULL          && \
     COMPRESS_filecode((ds)->dblk->diskptr->brick_name) >= 0 )
Determine if dataset ds is stored in a compressed format

Definition at line 2219 of file 3ddata.h.

Referenced by AFNI_choose_dataset_CB(), DRAW_choose_CB(), NOTES_choose_CB(), NUD_choose_CB(), patch_PLUGIN_dataset_links(), PLUG_choose_dataset_CB(), RCREND_choose_CB(), and REND_choose_CB().

#define DSET_CRUSH_BSTAT dset,
ii   
 

Value:

do{ if( DSET_VALID_BSTAT(dset,ii) )                             \
         INVALIDATE_BSTAT((dset)->stats->bstat[(ii)]) ; } while(0)
Mark the ii-th volume's brick statistics to be invalid in dataset dset.

Definition at line 2610 of file 3ddata.h.

Referenced by EDIT_substitute_brick(), and THD_add_bricks().

#define DSET_CUBICAL ds   
 

Value:

( fabs((ds)->daxes->xxdel) == fabs((ds)->daxes->yydel) && \
                           fabs((ds)->daxes->xxdel) == fabs((ds)->daxes->zzdel)   )
Determine if dataset ds has cubical voxels

Definition at line 2458 of file 3ddata.h.

Referenced by REND_finalize_dset_CB().

#define DSET_datum_constant ds       THD_datum_constant((ds)->dblk)
 

Definition at line 3336 of file 3ddata.h.

Referenced by CALC_read_opts(), FD_brick_to_series(), and main().

#define DSET_delete ds       THD_delete_3dim_dataset((ds),False)
 

Delete dataset ds's volumes and struct from memory.

Does not delete from disk

Definition at line 2666 of file 3ddata.h.

Referenced by AFNI_finalize_read_Web_CB(), AFNI_rescan_session_NEW(), basis_write_iresp(), basis_write_sresp(), COPY_main(), do_xrestore_stuff(), DRAW_saveas_finalize_CB(), EDT_calcmask(), get_options(), HI_read_opts(), init_floatvector_array(), main(), MRG_read_opts(), PC_read_opts(), process_NIML_AFNI_dataset(), r_new_resam_dset(), read_input_data(), RT_finish_dataset(), RT_registration_2D_atend(), RT_registration_2D_onevol(), RT_registration_2D_realtime(), RT_registration_3D_atend(), RT_registration_3D_onevol(), RT_registration_3D_realtime(), s2v_nodes2volume(), SUMA_FormAfnidset(), SUMA_Free_Generic_Prog_Options_Struct(), T3D_save_file_CB(), THD_copy_dset_subs(), THD_fetch_dataset(), THD_load_tcat(), THD_open_tcat(), THD_read_dvecmat(), THD_warp3D(), THD_zeropad(), TT_purge_atlas_big(), UC_read_opts(), VL_command_line(), write_bucket_data(), write_output(), and ZPAD_main().

#define DSET_DIRNAME ds   
 

Value:

(((ds)->dblk!=NULL && (ds)->dblk->diskptr!=NULL) \
                         ? ((ds)->dblk->diskptr->directory_name) : "\0" )
Return a pointer to the directory name of dataset ds

Definition at line 2329 of file 3ddata.h.

Referenced by main(), SUMA_VolParFromDset(), TAG_get_dset_CB(), and THD_write_3dim_dataset().

#define DSET_DX ds       ((ds)->daxes->xxdel)
 

Return grid spacing (voxel size) along x-axis of dataset ds

Definition at line 2392 of file 3ddata.h.

Referenced by AFNI_get_xhair_node(), DRAW_2D_circle(), DRAW_3D_sphere(), get_options(), HISTO_main(), main(), NUD_rotate(), remove_isolated_stuff(), RT_registration_2D_onevol(), RT_registration_3D_onevol(), RT_registration_3D_setup(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_LoadPrepInVol(), SUMA_MarchingCubesSurface(), SUMA_VolParFromDset(), THD_autonudge(), THD_dicomm_to_surefit(), THD_surefit_to_dicomm(), THD_write_1D(), VL_command_line(), and VOLREG_main().

#define DSET_DY ds       ((ds)->daxes->yydel)
 

Return grid spacing (voxel size) along y-axis of dataset ds

Definition at line 2396 of file 3ddata.h.

Referenced by AFNI_get_xhair_node(), DRAW_2D_circle(), DRAW_3D_sphere(), get_options(), HISTO_main(), main(), NUD_rotate(), RT_registration_2D_onevol(), RT_registration_3D_onevol(), RT_registration_3D_setup(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_LoadPrepInVol(), SUMA_MarchingCubesSurface(), SUMA_VolParFromDset(), THD_autonudge(), THD_dicomm_to_surefit(), THD_surefit_to_dicomm(), THD_write_1D(), VL_command_line(), and VOLREG_main().

#define DSET_DZ ds       ((ds)->daxes->zzdel)
 

Return grid spacing (voxel size) along z-axis of dataset ds

Definition at line 2400 of file 3ddata.h.

Referenced by AFNI_get_xhair_node(), DRAW_2D_circle(), DRAW_3D_sphere(), get_options(), HISTO_main(), main(), NUD_rotate(), RT_registration_3D_onevol(), RT_registration_3D_setup(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_LoadPrepInVol(), SUMA_MarchingCubesSurface(), SUMA_VolParFromDset(), THD_autonudge(), THD_dicomm_to_surefit(), THD_surefit_to_dicomm(), THD_write_1D(), VL_command_line(), and VOLREG_main().

#define DSET_FILECODE ds   
 

Value:

(((ds)->dblk!=NULL && (ds)->dblk->diskptr!=NULL) \
                         ? ((ds)->dblk->diskptr->filecode) : "\0" )
Return a pointer to the filecode of dataset ds (prefix+view)

Definition at line 2312 of file 3ddata.h.

Referenced by AFNI_dataset_slice(), BFIT_main(), CORREL_main(), DELAY_main(), DOT_main(), DRAW_finalize_dset_CB(), DRAW_saveas_finalize_CB(), DUMP_main(), EXTRACT_main(), HISTO_main(), main(), MASKAVE_main(), process_NIML_Node_ROI(), process_NIML_SUMA_ijk(), process_NIML_SUMA_node_normals(), RT_finish_dataset(), RT_registration_3D_realtime(), RT_tell_afni(), RT_tell_afni_one(), SCAT_main(), SUMA_VolParFromDset(), TAG_get_dset_CB(), THD_dataset_info(), and VOLREG_main().

#define DSET_FIX_NAMES ds   
 

Value:

( strcpy((ds)->self_name,(ds)->dblk->diskptr->directory_name), \
    strcat((ds)->self_name,(ds)->dblk->diskptr->filecode)      , \
    strcpy((ds)->label1   ,(ds)->dblk->diskptr->filecode)      , \
    strcpy((ds)->label2   ,THD_DEFAULT_LABEL) )
Macro to load the self_name and labels of a dataset with values computed from the filenames; replaces user control/input of these values in to3d

Definition at line 2580 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define DSET_FUNCLABEL ds   
 

Value:

( ISFUNC(ds) ? FUNC_label[(ds)->func_type]      \
                                        : ANAT_prefixstr[(ds)->func_type] )

Definition at line 1943 of file 3ddata.h.

#define DSET_GRAPHABLE ds   
 

Value:

( ISVALID_3DIM_DATASET(ds) && DSET_INMEMORY(ds)      && \
                             (ds)->wod_flag == False                            && \
                             ( DSET_ONDISK(ds) || DSET_LOADED(ds) && DSET_LOCKED(ds) ) )
Determine if a graph window can be opened for dataset ds.

Cannot graph warp-on-demand datasets.

Definition at line 2470 of file 3ddata.h.

Referenced by AFNI_choose_dataset_CB(), AFNI_fimmer_compute(), AFNI_fimmer_execute(), AFNI_fimmer_setignore(), AFNI_fimmer_setort(), AFNI_fimmer_setpolort(), AFNI_fimmer_setref(), AFNI_setup_viewing(), AFNI_underlay_CB(), AFNI_view_xyz_CB(), fim3d_fimmer_compute(), and main().

#define DSET_HEADNAME ds   
 

Value:

( ((ds)->tcat_list != NULL) ? (ds)->tcat_list     \
                          : ((ds)->dblk!=NULL && (ds)->dblk->diskptr!=NULL) \
                          ? ((ds)->dblk->diskptr->header_name) : "\0" )
Return a pointer to the .HEAD filename of dataset ds

Definition at line 2317 of file 3ddata.h.

Referenced by AFNI_fimmer_execute(), AFNI_follower_dataset(), AFNI_force_adoption(), AFNI_process_plugout(), do_xrestore_stuff(), DRAW_saveas_finalize_CB(), form_clusters(), main(), PLUTO_commandstring(), RCREND_widgets_to_state(), REND_widgets_to_state(), s2v_nodes2volume(), SUMA_FormAfnidset(), THD_3dim_from_block(), THD_autonudge(), THD_check_idcodes(), VL_command_line(), write_bucket(), write_bucket_data(), write_output(), and write_results().

#define DSET_IDCODE ds       (&((ds)->idcode))
 

Return a pointer to the ID code of dataset ds

Definition at line 2336 of file 3ddata.h.

#define DSET_IDCODE_STR ds       ((ds)->idcode.str)
 

Return the ID code string

Definition at line 2340 of file 3ddata.h.

#define DSET_IN_3DARR name,
nn       ((name)->ar[(nn)])
 

Macro to access the nn-th dataset in AFNI dataset array name

Definition at line 2805 of file 3ddata.h.

#define DSET_index_to_ix ds,
ii       ( (ii) % (ds)->daxes->nxx)
 

Find the x-axis index of a 3D array index in dataset ds

Definition at line 2442 of file 3ddata.h.

Referenced by EDT_calcmask(), and main().

#define DSET_index_to_jy ds,
ii       ( ((ii) / (ds)->daxes->nxx) % (ds)->daxes->nyy )
 

Find the y-axis index of a 3D array index in dataset ds

Definition at line 2446 of file 3ddata.h.

Referenced by EDT_calcmask(), and main().

#define DSET_index_to_kz ds,
ii       ( (ii) /((ds)->daxes->nxx * (ds)->daxes->nyy ))
 

Find the z-axis index of a 3D array index in dataset ds

Definition at line 2450 of file 3ddata.h.

Referenced by EDT_calcmask(), and main().

#define DSET_INMEMORY ds   
 

Value:

( ISVALID_DSET(ds) && (ds)->dblk!=NULL &&                                      \
    (ds)->dblk->malloc_type!=DATABLOCK_MEM_UNDEFINED &&                          \
    ( (ds)->dblk->diskptr->storage_mode!=STORAGE_UNDEFINED || DSET_LOADED(ds) ) )
Determine if dataset ds is loadable into memory

Definition at line 2233 of file 3ddata.h.

Referenced by AFNI_crosshair_label(), AFNI_dataset_slice(), AFNI_setup_viewing(), DRAW_choose_CB(), NUD_choose_CB(), and PLUGIN_dset_check().

#define DSET_IS_1D ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&           \
                         ISVALID_DISKPTR((ds)->dblk->diskptr) &&                   \
                         (ds)->dblk->diskptr->storage_mode == STORAGE_BY_1D )
Determine if dataset ds is stored in a 1D file on disk

Definition at line 2168 of file 3ddata.h.

Referenced by AFNI_write_dataset_CB(), create_bucket(), EDIT_dset_items(), main(), THD_delete_3dim_dataset(), THD_write_1D(), and THD_write_3dim_dataset().

#define DSET_IS_3D ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&           \
                         ISVALID_DISKPTR((ds)->dblk->diskptr) &&                   \
                         (ds)->dblk->diskptr->storage_mode == STORAGE_BY_3D )
Determine if dataset ds is stored in a 3D file on disk

Definition at line 2174 of file 3ddata.h.

Referenced by create_bucket(), EDIT_dset_items(), main(), THD_delete_3dim_dataset(), and THD_write_3dim_dataset().

#define DSET_IS_ANALYZE ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&       \
                              ISVALID_DISKPTR((ds)->dblk->diskptr) &&               \
                              (ds)->dblk->diskptr->storage_mode == STORAGE_BY_ANALYZE )
Determine if dataset ds is stored in a ANALYZE file on disk

Definition at line 2125 of file 3ddata.h.

Referenced by AFNI_write_dataset_CB(), main(), THD_delete_3dim_dataset(), and THD_write_3dim_dataset().

#define DSET_IS_BRIK ds   
 

Value:

( ISVALID_DSET(ds) && (ds)->dblk!=NULL && \
                           (ds)->dblk->diskptr->storage_mode == STORAGE_BY_BRICK )
Determine if dataset ds is stored in a BRIK file on disk

Definition at line 2104 of file 3ddata.h.

Referenced by main(), and THD_dataset_info().

#define DSET_IS_CTFMRI ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&       \
                             ISVALID_DISKPTR((ds)->dblk->diskptr) &&               \
                             (ds)->dblk->diskptr->storage_mode == STORAGE_BY_CTFMRI )
Determine if dataset ds is stored in a CTFMRI file on disk

Definition at line 2136 of file 3ddata.h.

Referenced by AFNI_write_dataset_CB(), main(), THD_delete_3dim_dataset(), and THD_write_3dim_dataset().

#define DSET_IS_CTFSAM ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&       \
                             ISVALID_DISKPTR((ds)->dblk->diskptr) &&               \
                             (ds)->dblk->diskptr->storage_mode == STORAGE_BY_CTFSAM )
Determine if dataset ds is stored in a CTFSAM file on disk

Definition at line 2147 of file 3ddata.h.

Referenced by AFNI_write_dataset_CB(), main(), THD_delete_3dim_dataset(), and THD_write_3dim_dataset().

#define DSET_IS_MALLOC ds       DBLK_IS_MALLOC((ds)->dblk)
 

Check if dataset ds is loaded into memory using malloc()

Definition at line 2730 of file 3ddata.h.

Referenced by THD_insert_series().

#define DSET_IS_MASTERED ds       DBLK_IS_MASTERED((ds)->dblk)
 

Check if dataset ds is "mastered": gets its data from someone else.

Mastered datasets are specified on the command line with the [a..b] syntax, etc.

Definition at line 2744 of file 3ddata.h.

Referenced by main(), and THD_write_3dim_dataset().

#define DSET_IS_MINC ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&       \
                           ISVALID_DISKPTR((ds)->dblk->diskptr) &&               \
                           (ds)->dblk->diskptr->storage_mode == STORAGE_BY_MINC )
Determine if dataset ds is stored in a MINC file on disk

Definition at line 2114 of file 3ddata.h.

Referenced by AFNI_write_dataset_CB(), main(), THD_delete_3dim_dataset(), THD_fetch_dataset(), and THD_write_3dim_dataset().

#define DSET_IS_MMAP ds       DBLK_IS_MMAP((ds)->dblk)
 

Check if dataset ds is loaded into memory using mmap()

Definition at line 2734 of file 3ddata.h.

#define DSET_IS_MPEG ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&       \
                           ISVALID_DISKPTR((ds)->dblk->diskptr) &&               \
                           (ds)->dblk->diskptr->storage_mode == STORAGE_BY_MPEG )
Determine if dataset ds is stored in a MPEG file on disk

Definition at line 2204 of file 3ddata.h.

Referenced by main().

#define DSET_IS_NIFTI ds   
 

Value:

( ISVALID_DSET(ds) && ISVALID_DBLK((ds)->dblk) &&        \
                            ISVALID_DISKPTR((ds)->dblk->diskptr) &&                \
                            (ds)->dblk->diskptr->storage_mode == STORAGE_BY_NIFTI )
Determine if dataset ds is stored in a NIFTI file on disk

Definition at line 2180 of file 3ddata.h.

Referenced by AFNI_write_dataset_CB(), main(), THD_delete_3dim_dataset(), and THD_fetch_dataset().

#define DSET_IS_SHARED ds       DBLK_IS_SHARED((ds)->dblk)
 

Check if dataset ds is loaded into shared memory

Definition at line 2738 of file 3ddata.h.

#define DSET_IS_TCAT ds       (ISVALID_DSET(ds) && (ds)->tcat_list != NULL)
 

Dataset is tcat-ed?

Definition at line 2044 of file 3ddata.h.

Referenced by read_input_data(), THD_load_datablock(), THD_write_3dim_dataset(), and write_bucket_data().

#define DSET_IS_VOLUMES ds   
 

Value:

( ISVALID_DSET(ds) &&                                    \
                              ISVALID_DBLK((ds)->dblk) &&                            \
                              ISVALID_DISKPTR((ds)->dblk->diskptr) &&                \
                              (ds)->dblk->diskptr->storage_mode == STORAGE_BY_VOLUMES )
Determine if dataset ds is stored in volumes files rather than 1 big BRIK

Definition at line 2192 of file 3ddata.h.

Referenced by THD_delete_3dim_dataset(), THD_fetch_dataset(), and THD_write_3dim_dataset().

#define DSET_ixyz_to_index ds,
ix,
jy,
kz       ((ix)+((jy)+(kz)*(ds)->daxes->nyy)*(ds)->daxes->nxx)
 

Convert a triple-index (ix,jy,kz) to a single 3D index for dataset ds

Definition at line 2454 of file 3ddata.h.

Referenced by EDT_calcmask(), and main().

#define DSET_KEYWORDS ds       ((ds)->keywords)
 

Definition at line 2567 of file 3ddata.h.

Referenced by main(), and THD_dataset_info().

#define DSET_KEYWORDS_HAS ds,
ss       THD_string_has( DSET_KEYWORDS((ds)) , (ss) )
 

Definition at line 2572 of file 3ddata.h.

#define DSET_KILL_STATS ds   
 

Value:

do{ if( (ds)->stats != NULL ){                           \
         REMOVEFROM_KILL( (ds)->kl, (ds)->stats->bstat ) ; \
         REMOVEFROM_KILL( (ds)->kl, (ds)->stats ) ;        \
         KILL_STATISTIC( (ds)->stats ) ;                   \
         (ds)->stats = NULL ; } } while(0)
Delete all the sub-brick statistics for dataset ds.

Definition at line 2616 of file 3ddata.h.

#define DSET_load ds       THD_load_datablock( (ds)->dblk )
 

Load dataset ds's sub-bricks into memory.

If it is already loaded, does nothing (so you can call this without much penalty).

Definition at line 2647 of file 3ddata.h.

Referenced by AFNI_func_overlay(), AFNI_ttatlas_overlay(), AFNI_vnlist_func_overlay(), AFNI_vol2surf_func_overlay(), avg_epochs(), BFIT_main(), BFIT_prepare_dataset(), CALC_read_opts(), calculate_results(), CLUST_main(), CORREL_main(), do_xrestore_stuff(), DRAW_finalize_dset_CB(), DRAW_receiver(), DRAW_saveas_finalize_CB(), DRAW_ttatlas_CB(), DSET2_func(), DSET_cor(), edgeDetect(), ENTROPY_dataset(), Fourier_Filter_Driver(), HEMISUB_main(), HISTO_main(), IMREG_main(), init_floatvector_array(), load_histo(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), MASKAVE_main(), NUD_finalize_dset_CB(), PC_read_opts(), PERMTEST_main(), PLUTO_4D_to_nothing(), POWER_main(), process_args(), process_NIML_Node_ROI(), r_init_afni_vars(), r_init_Alg_values(), RCREND_overlay_ttatlas(), RCREND_reload_dataset(), RCREND_reload_func_dset(), REND_overlay_ttatlas(), REND_reload_dataset(), REND_reload_func_dset(), REORDER_main(), RIC_CalcCoeffAB(), RIC_CalcVoxelMeans(), RIC_CorrectDataset(), ROIPLOT_main(), SCAT_main(), SUMA_Get_isosurface_datasets(), THD_autonudge(), THD_copy_dset_subs(), THD_dataset_tshift(), THD_extract_array(), THD_fetch_dataset(), THD_get_voxel(), THD_insert_series(), THD_load_tcat(), THD_makemask(), THD_mean_brick(), THD_median_brick(), THD_open_3dcalc(), THD_outlier_count(), THD_rms_brick(), THD_warp3D(), THD_write_minc(), THD_write_nifti(), THD_zeropad(), THRESH_main(), TT_whereami(), UC_read_opts(), VL_command_line(), VOLREG_main(), and WINsorize().

#define DSET_LOADED ds       ( THD_count_databricks((ds)->dblk) == DSET_NVALS(ds) )
 

Check if dataset ds if fully loaded into memory.

If return is 0 (false), you could try DSET_load(ds)

Definition at line 2683 of file 3ddata.h.

Referenced by AFNI_vnlist_func_overlay(), AFNI_vol2surf_func_overlay(), CALC_read_opts(), do_xrestore_stuff(), EDIT_one_dataset(), ENTROPY_dataset(), init_floatvector_array(), main(), PC_read_opts(), process_NIML_Node_ROI(), r_fill_resampled_data_brick(), r_init_afni_vars(), r_init_Alg_values(), read_input_data(), THD_autonudge(), THD_copy_dset_subs(), THD_dataset_tshift(), THD_insert_series(), THD_load_tcat(), THD_makemask(), THD_mean_brick(), THD_median_brick(), THD_open_3dcalc(), THD_outlier_count(), THD_rms_brick(), THD_warp3D(), THD_write_1D(), THD_write_minc(), THD_write_nifti(), THD_zeropad(), UC_read_opts(), VL_command_line(), and VOLREG_main().

#define DSET_lock ds       DBLK_lock((ds)->dblk)
 

Lock dataset ds into memory

Definition at line 2687 of file 3ddata.h.

Referenced by AFNI_read_images(), AFNI_read_inputs(), DRAW_finalize_dset_CB(), DRAW_receiver(), DRAW_saveas_finalize_CB(), NUD_finalize_dset_CB(), process_NIML_Node_ROI(), r_fill_resampled_data_brick(), RT_fim_recurse(), RT_start_dataset(), and THD_open_3dcalc().

#define DSET_LOCKED ds       DBLK_LOCKED((ds)->dblk)
 

Check if dataset ds is locked into memory

Definition at line 2695 of file 3ddata.h.

#define DSET_mallocize ds       DBLK_mallocize((ds)->dblk)
 

Force this dataset to be loaded into memory using malloc().

If you are altering the dataset contents, this is required, since a mmap()-ed dataset is readonly.

Definition at line 2702 of file 3ddata.h.

Referenced by CALC_read_opts(), do_xrestore_stuff(), DRAW_finalize_dset_CB(), DRAW_receiver(), DRAW_saveas_finalize_CB(), main(), NUD_finalize_dset_CB(), process_NIML_Node_ROI(), THD_dataset_tshift(), THD_fetch_dataset(), THD_load_tcat(), THD_niml_to_dataset(), THD_open_3dcalc(), and THD_open_tcat().

#define DSET_MARK_FOR_DEATH ds       do{ if( ISVALID_DSET(ds) && ds->death_mark >= 0 ) ds->death_mark = DOOMED ; } while(0)
 

Mark a dataset to be eliminated by AFNI_mark_for_death() and AFNI_andersonville().

Definition at line 2029 of file 3ddata.h.

Referenced by AFNI_mark_for_death(), AFNI_marks_transform_CB(), and AFNI_rescan_session_OLD().

#define DSET_MARK_FOR_IMMORTALITY ds       do{ if( ISVALID_DSET(ds) ) ds->death_mark = -1 ; } while(0)
 

Mark a dataset to be ineligible for elimination during AFNI_rescan_session().

Definition at line 2034 of file 3ddata.h.

Referenced by AFNI_read_inputs().

#define DSET_MARK_FOR_NORMAL ds       do{ if( ISVALID_DSET(ds) ) ds->death_mark = 0 ; } while(0)
 

Mark a dataset to be eligible for elimination if the need arises.

Definition at line 2039 of file 3ddata.h.

#define DSET_mmapize ds       DBLK_mmapize((ds)->dblk)
 

Force this dataset to be loaded into memory using mmap() You cannot alter any sub-brick data, since mmap() is done in readonly mode.

Definition at line 2708 of file 3ddata.h.

#define DSET_NUM_TIMES ds       ( ((ds)->taxis == NULL) ? 1 : (ds)->taxis->ntt )
 

Return number of time points in dataset ds.

If value is 1, dataset is not time-dependent, but it still may have multiple sub-bricks (if it is a bucket dataset, for example)

Definition at line 2357 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_bucket_CB(), AFNI_choose_dataset_CB(), AFNI_fimmer_compute(), AFNI_follower_dataset(), AFNI_set_viewpoint(), AFNI_setup_viewing(), AFNI_time_index_CB(), AFNI_write_many_dataset_CB(), applyMask(), avg_epochs(), CALC_read_opts(), calculate_results(), check_for_valid_inputs(), CORREL_main(), DELAY_main(), DRAW_choose_CB(), dset_to_mri(), edgeDetect(), EDIT_opts(), eval_registration(), extract_ts_array(), fim3d_fimmer_compute(), Fourier_Filter_Driver(), get_options(), IMREG_main(), initialize_filters(), initialize_rms_arrays(), initialize_state_history(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), NOTES_choose_CB(), NUD_choose_CB(), output_rms_arrays(), output_state_history(), patch_PLUGIN_dataset_links(), PERMTEST_compute(), PERMTEST_main(), PLUG_choose_dataset_CB(), PLUGIN_dset_check(), PLUTO_4D_to_nothing(), populate_nifti_image(), POWER_main(), RCREND_choose_CB(), read_input_data(), REND_choose_CB(), REORDER_main(), RT_registration_2D_atend(), RT_registration_2D_realtime(), RT_registration_3D_atend(), RT_registration_3D_realtime(), set_fim_thr_level(), STAVG_main(), T3D_save_file_CB(), terminate_program(), THD_dataset_info(), THD_outlier_count(), THD_warp3D(), THD_write_minc(), THRESH_compute(), and write_bucket_data().

#define DSET_NUM_TTOFF ds       ( ((ds)->taxis == NULL) ? 0 : (ds)->taxis->nsl )
 

Return number of time-axis slice offsets for datsaet ds.

Will be zero for non-time-dependent datasets, and may be zero or positive for time-dependent datasets

Definition at line 2509 of file 3ddata.h.

Referenced by main(), populate_nifti_image(), and write_results().

#define DSET_NVALS ds       ( (ds)->dblk->nvals )
 

Return number of sub-bricks in dataset ds

Definition at line 2372 of file 3ddata.h.

Referenced by AFNI_brick_to_mri(), AFNI_bucket_CB(), AFNI_bucket_label_CB(), AFNI_choose_dataset_CB(), AFNI_fimmer_compute(), AFNI_fimmer_redisplay(), AFNI_func_overlay(), AFNI_setup_viewing(), AFNI_time_index_CB(), AFNI_vnlist_func_overlay(), AFNI_write_many_dataset_CB(), alloc_output_mem(), B2F_read_opts(), BFIT_main(), BFIT_prepare_dataset(), BUCK_read_opts(), CALC_read_opts(), check_for_valid_inputs(), copy_dset(), COPY_main(), CORREL_main(), do_xrestore_stuff(), DRAW_choose_CB(), DRAW_copy_dset(), DT_read_opts(), DUMP_main(), dump_surf_3dt(), EDIT_full_copy(), EDIT_one_dataset(), fill_afni_struct(), get_options(), HISTO_main(), init_floatvector_array(), initialize_program(), load_histo(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), MASKAVE_main(), NOTES_choose_CB(), NUD_brick_av_label_CB(), NUD_choose_CB(), NUD_doall_CB(), NUD_finalize_dset_CB(), NUD_update_base(), patch_PLUGIN_dataset_links(), PC_read_opts(), PLUG_choose_dataset_CB(), PLUTO_4D_to_nothing(), populate_nifti_image(), PRIC_main(), process_all_datasets(), process_args(), process_dataset(), r_set_afni_s_from_dset(), RCREND_choose_av_CB(), RCREND_choose_av_label_CB(), RCREND_choose_CB(), RCREND_finalize_dset_CB(), RCREND_finalize_func_CB(), RCREND_state_to_widgets(), RCREND_xhair_recv(), read_input_data(), REND_choose_av_CB(), REND_choose_av_label_CB(), REND_choose_CB(), REND_finalize_dset_CB(), REND_finalize_func_CB(), REND_state_to_widgets(), RIC_CalcCoeffAB(), RIC_CalcVoxelMeans(), RIC_CorrectDataset(), ROIPLOT_main(), RT_fim_recurse(), RT_tell_afni_one(), SCAT_main(), set_surf_results(), SUMA_Get_isosurface_datasets(), SUMA_LoadPrepInVol(), SUMA_SendDset_Afni(), TCAT_read_opts(), THD_add_bricks(), THD_autonudge(), THD_average_timeseries(), THD_dataset_rowfillin(), THD_dataset_to_niml(), THD_dataset_tshift(), THD_dataset_zfillin(), THD_extract_float_brick(), THD_fetch_dataset(), THD_get_voxel(), THD_insert_series(), THD_load_tcat(), THD_makemask(), thd_mask_from_brick(), THD_mean_brick(), THD_median_brick(), THD_need_brick_factor(), THD_open_dataset(), THD_open_tcat(), THD_rms_brick(), THD_subbrick_to_niml(), THD_update_one_bstat(), THD_warp3D(), THD_write_1D(), THD_write_minc(), THD_write_nifti(), THD_zerofill_dataset(), THD_zeropad(), UC_read_opts(), validate_datasets(), validate_v2s_inputs(), VL_command_line(), VOLREG_main(), and ZCAT_read_opts().

#define DSET_NVALS_PER_TIME ds       ( (ds)->dblk->nvals / DSET_NUM_TIMES(ds) )
 

Return number of values stored at each time point for dataset ds.

Will always be 1 in the current version of AFNI! (Except for bucket datasets, that is, damn it.)

Definition at line 2368 of file 3ddata.h.

Referenced by IMREG_main(), main(), STAVG_main(), THD_dataset_info(), and VOLREG_main().

#define DSET_NVOX ds       ( (ds)->daxes->nxx * (ds)->daxes->nyy * (ds)->daxes->nzz )
 

Return number of voxels in each sub-brick of dataset ds

Definition at line 2376 of file 3ddata.h.

Referenced by AFNI_ttatlas_overlay(), afni_vol2surf(), applyMask(), BFIT_main(), BFIT_prepare_dataset(), compute_results(), CORREL_main(), do_xrestore_stuff(), DRAW_ttatlas_CB(), DSET_cor(), edgeDetect(), form_clusters(), Fourier_Filter_Driver(), get_options(), HI_read_opts(), HISTO_main(), init_floatvector_array(), initialize_program(), load_histo(), main(), MASKAVE_main(), MRG_read_opts(), PC_read_opts(), RCREND_overlay_ttatlas(), RCREND_reload_func_dset(), read_input_data(), REND_overlay_ttatlas(), REND_reload_func_dset(), ROIPLOT_main(), s2v_nodes2volume(), SCAT_main(), SUMA_Get_isosurface_datasets(), SUMA_LoadPrepInVol(), THD_add_bricks(), THD_cmass(), THD_extract_array(), THD_extract_float_brick(), THD_get_voxel(), THD_insert_series(), THD_makemask(), thd_mask_from_brick(), THD_mean_brick(), THD_median_brick(), THD_outlier_count(), THD_rms_brick(), THD_subbrick_to_niml(), THD_write_minc(), UC_read_opts(), validate_datasets(), and validate_v2s_inputs().

#define DSET_NX ds       ((ds)->daxes->nxx)
 

Return number of voxels along x-axis of dataset ds

Definition at line 2380 of file 3ddata.h.

Referenced by auto_initialize(), CALC_read_opts(), center_of_mass(), check_for_valid_inputs(), connectivity_tests(), DRAW_2D_circle(), DRAW_2D_expand(), DRAW_3D_expand(), DRAW_3D_sphere(), DRAW_into_dataset(), DRAW_receiver(), EDT_calcmask(), estimate_field(), estpdf_initialize(), get_options(), HISTO_main(), initialize_program(), insert_list(), main(), PC_read_opts(), process_all_datasets(), process_NIML_Node_ROI(), r_init_afni_vars(), RCREND_finalize_dset_CB(), RCREND_load_dsl(), RCREND_state_to_widgets(), read_input_data(), remove_field(), remove_isolated_stuff(), REND_finalize_dset_CB(), REND_load_dsl(), REND_state_to_widgets(), resample(), RT_registration_2D_onevol(), RT_registration_2D_setup(), segment_envelope(), segment_imarr(), segment_volume(), segment_x_slices(), segment_y_slices(), segment_z_slices(), set_3dmm_bounds(), set_surf_results(), SUMA_ConvexHullSurface(), SUMA_Find_IminImax(), SUMA_Find_IminImax_Avg(), SUMA_FormAfnidset(), SUMA_isSkin(), SUMA_LoadPrepInVol(), SUMA_make_vnlist(), SUMA_MarchingCubesSurface(), SUMA_SkullMask(), SUMA_VolDims(), SUMA_VolParFromDset(), target_into_dataset(), THD_autonudge(), THD_average_timeseries(), THD_dataset_rowfillin(), THD_dataset_tshift(), THD_dataset_zfillin(), THD_dicomm_to_surefit(), THD_get_dset_row(), THD_get_dset_rowcount(), THD_open_tcat(), THD_put_dset_row(), THD_surefit_to_dicomm(), THD_timeof_vox(), THD_warp3D(), THD_write_1D(), THD_zeropad(), TT_whereami(), VL_command_line(), VOLREG_main(), WINsorize(), and write_afni_data().

#define DSET_NY ds       ((ds)->daxes->nyy)
 

Return number of voxels along y-axis of dataset ds

Definition at line 2384 of file 3ddata.h.

Referenced by auto_initialize(), CALC_read_opts(), center_of_mass(), check_for_valid_inputs(), connectivity_tests(), DRAW_2D_circle(), DRAW_2D_expand(), DRAW_3D_expand(), DRAW_3D_sphere(), DRAW_into_dataset(), DRAW_receiver(), EDIT_dset_items(), EDT_calcmask(), estimate_field(), estpdf_initialize(), get_options(), HISTO_main(), initialize_program(), insert_list(), main(), PC_read_opts(), process_all_datasets(), process_NIML_Node_ROI(), r_init_afni_vars(), RCREND_finalize_dset_CB(), RCREND_load_dsl(), RCREND_state_to_widgets(), read_input_data(), remove_field(), remove_isolated_stuff(), REND_finalize_dset_CB(), REND_load_dsl(), REND_state_to_widgets(), resample(), RT_registration_2D_onevol(), RT_registration_2D_setup(), segment_envelope(), segment_imarr(), segment_volume(), segment_x_slices(), segment_y_slices(), segment_z_slices(), set_3dmm_bounds(), set_surf_results(), SUMA_ConvexHullSurface(), SUMA_Find_IminImax(), SUMA_Find_IminImax_Avg(), SUMA_FormAfnidset(), SUMA_isSkin(), SUMA_LoadPrepInVol(), SUMA_make_vnlist(), SUMA_MarchingCubesSurface(), SUMA_SkullMask(), SUMA_VolDims(), SUMA_VolParFromDset(), target_into_dataset(), THD_autonudge(), THD_average_timeseries(), THD_dataset_rowfillin(), THD_dataset_tshift(), THD_dataset_zfillin(), THD_dicomm_to_surefit(), THD_get_dset_row(), THD_get_dset_rowcount(), THD_open_tcat(), THD_put_dset_row(), THD_surefit_to_dicomm(), THD_timeof_vox(), THD_warp3D(), THD_write_1D(), THD_write_3dim_dataset(), THD_zeropad(), TT_whereami(), VL_command_line(), VOLREG_main(), WINsorize(), and write_afni_data().

#define DSET_NZ ds       ((ds)->daxes->nzz)
 

Return number of voxels along z-axis of dataset ds

Definition at line 2388 of file 3ddata.h.

Referenced by AFNI_ttatlas_overlay(), auto_initialize(), CALC_read_opts(), center_of_mass(), check_for_valid_inputs(), connectivity_tests(), DRAW_2D_circle(), DRAW_2D_expand(), DRAW_3D_expand(), DRAW_3D_sphere(), DRAW_into_dataset(), DRAW_receiver(), DT_read_opts(), EDIT_dset_items(), EDT_calcmask(), estimate_field(), estpdf_initialize(), get_options(), HISTO_main(), initialize_program(), main(), PC_read_opts(), process_all_datasets(), r_init_afni_vars(), RCREND_finalize_dset_CB(), RCREND_load_dsl(), RCREND_state_to_widgets(), read_input_data(), remove_field(), remove_isolated_stuff(), REND_finalize_dset_CB(), REND_load_dsl(), REND_state_to_widgets(), resample(), RT_registration_2D_close(), RT_registration_2D_onevol(), RT_registration_2D_setup(), segment_envelope(), segment_volume(), segment_x_slices(), segment_y_slices(), segment_z_slices(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_FormAfnidset(), SUMA_isSkin(), SUMA_make_vnlist(), SUMA_MarchingCubesSurface(), SUMA_VolDims(), SUMA_VolParFromDset(), target_into_dataset(), THD_autonudge(), THD_dataset_rowfillin(), THD_dataset_tshift(), THD_dataset_zfillin(), THD_dicomm_to_surefit(), THD_get_dset_row(), THD_get_dset_rowcount(), THD_open_tcat(), THD_put_dset_row(), THD_surefit_to_dicomm(), THD_warp3D(), THD_write_1D(), THD_write_3dim_dataset(), THD_zeropad(), TT_whereami(), VL_command_line(), VOLREG_main(), WINsorize(), and write_afni_data().

#define DSET_ONDISK ds   
 

Value:

( ISVALID_DSET(ds) && (ds)->dblk!=NULL && \
                          (ds)->dblk->diskptr->storage_mode!=STORAGE_UNDEFINED )
Determine if dataset ds is actually stored on disk

Definition at line 2099 of file 3ddata.h.

Referenced by DUP_main(), and THD_3dim_from_block().

#define DSET_ORDERED d1,
d2   
 

Value:

( ( (d1)->view_type < (d2)->view_type ) || \
    ( (d1)->view_type==(d2)->view_type && (d1)->func_type<(d2)->func_type ) )
Determine if two datasets are properly ordered

Definition at line 2809 of file 3ddata.h.

#define DSET_PREFIX ds   
 

Value:

(((ds)->dblk!=NULL && (ds)->dblk->diskptr!=NULL) \
                       ? ((ds)->dblk->diskptr->prefix) : "\0" )
Return a pointer to the prefix of dataset ds

Definition at line 2304 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), AFNI_rescan_session_NEW(), check_for_valid_inputs(), DELAY_main(), DRAW_copy_dset(), DUMP_main(), EXTRACT_main(), HISTO_main(), main(), RT_fim_recurse(), SUMA_SendDset_Afni(), SUMA_VolParFromDset(), THD_dset_in_session(), THD_init_session(), THD_newprefix(), THD_write_1D(), THD_write_3dim_dataset(), and write_bucket_data().

#define DSET_PREFIXSTR ds   
 

Value:

( ISFUNC(ds) ? FUNC_prefixstr[(ds)->func_type]  \
                                        : ANAT_prefixstr[(ds)->func_type] )

Definition at line 1940 of file 3ddata.h.

Referenced by AFNI_choose_dataset_CB().

#define DSET_PRINCIPAL_INDEX   DSET_PRINCIPAL_VALUE
 

Synonym for DSET_PRINCIPAL_VALUE

Definition at line 2292 of file 3ddata.h.

#define DSET_PRINCIPAL_VALUE ds   
 

Value:

( ISANAT(ds) ? ANAT_ival_zero[(ds)->func_type] \
                                              : FUNC_ival_fim[(ds)->func_type] )
Return the volume index of the "most important" sub-brick in dataset ds.

This is still used in places, but is fairly obsolete

Definition at line 2287 of file 3ddata.h.

Referenced by DSET_cor(), EDIT_main(), initialize_program(), main(), PLUGIN_dset_check(), read_afni_data(), and write_afni_data().

#define DSET_SESSNAME   DSET_DIRNAME
 

Definition at line 2332 of file 3ddata.h.

#define DSET_shareize ds       DBLK_shareize((ds)->dblk)
 

Force this dataset to be loaded into shared memory. You cannot alter any sub-brick data, since is done in readonly mode.

Definition at line 2714 of file 3ddata.h.

#define DSET_superlock ds       DBLK_superlock((ds)->dblk)
 

Super-lock dataset ds into memory.

Super-locked datasets will not be unlocked by DSET_unlock

Definition at line 2726 of file 3ddata.h.

Referenced by process_NIML_AFNI_dataset(), and THD_fetch_dataset().

#define DSET_SWAP d1,
d2       (dt=(d1),(d1)=(d2),(d2)=dt)
 

Swap 2 dataset pointers (thru pointer dt)

Definition at line 2815 of file 3ddata.h.

#define DSET_THRESH_INDEX   DSET_THRESH_VALUE
 

Definition at line 2300 of file 3ddata.h.

Referenced by CLUST_main(), and EDIT_opts().

#define DSET_THRESH_VALUE ds       (ISANAT((ds)) ? -1 : FUNC_ival_thr[(ds)->func_type])
 

Return the volume index of the "threshold" sub-brick in dataset ds.

This is analogous to DSET_PRINCIPAL_VALUE, and is also sort-of-obsolete.

Definition at line 2298 of file 3ddata.h.

Referenced by AFNI_dataset_slice(), main(), RCREND_set_thr_pval(), and REND_set_thr_pval().

#define DSET_TIMEDURATION ds       ( ((ds)->taxis == NULL) ? 0.0 : (ds)->taxis->ttdur )
 

Return the time duration of image acquisition for dataset ds.

Is always 0 in current version of AFNI (was intended for true 3D echo-volume imaging).

Definition at line 2491 of file 3ddata.h.

Referenced by main(), and THD_warp3D().

#define DSET_TIMEORIGIN ds       ( ((ds)->taxis == NULL) ? 0.0 : (ds)->taxis->ttorg )
 

Return the time origin for dataset ds.

Is always 0 in current version of AFNI.

Definition at line 2485 of file 3ddata.h.

Referenced by main(), populate_nifti_image(), and THD_warp3D().

#define DSET_TIMESTEP ds       ( ((ds)->taxis == NULL) ? 0.0 : (ds)->taxis->ttdel )
 

Return the TR for dataset ts; will be 0 if not time-dependent.

Definition at line 2477 of file 3ddata.h.

Referenced by Fourier_Filter_Driver(), get_options(), main(), POWER_main(), STAVG_main(), THD_dataset_tshift(), THD_open_tcat(), THD_write_minc(), VOLREG_main(), and write_ts_array().

#define DSET_TIMEUNITS ds   
 

Value:

( ((ds)->taxis == NULL) ? ILLEGAL_TYPE             \
                                                         : (ds)->taxis->units_type )
Return the time-step units code for dataset ds.

Will be one of

  • UNITS_MSEC_TYPE milliseconds
  • UNITS_SEC_TYPE seconds
  • UNITS_HZ_TYPE Hertz
  • ILLEGAL_TYPE not a time-dependent dataset (d'oh)

Definition at line 2501 of file 3ddata.h.

Referenced by calculate_results(), Fourier_Filter_Driver(), get_options(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), PLUTO_4D_to_nothing(), populate_nifti_image(), POWER_main(), read_input_data(), STAVG_main(), THD_warp3D(), and THD_write_1D().

#define DSET_TR   DSET_TIMESTEP
 

Definition at line 2479 of file 3ddata.h.

Referenced by basis_write_iresp(), basis_write_sresp(), DT_read_opts(), main(), read_input_data(), THD_warp3D(), and THD_write_1D().

#define DSET_TYPESTR ds   
 

Value:

( ISFUNC(ds) ? FUNC_typestr[(ds)->func_type]     \
                                        : ANAT_typestr[(ds)->func_type] )

Definition at line 1946 of file 3ddata.h.

#define DSET_unload ds       THD_purge_datablock( (ds)->dblk , DATABLOCK_MEM_ANY )
 

Unload dataset ds's sub-bricks from memory.

Won't do anything if the dataset is locked into memory

Definition at line 2653 of file 3ddata.h.

Referenced by AFNI_rescan_session_NEW(), avg_epochs(), BFIT_prepare_dataset(), calculate_results(), CLUST_main(), COPY_main(), CORREL_main(), do_xrestore_stuff(), DRAW_finalize_dset_CB(), DRAW_quit_CB(), DRAW_saveas_finalize_CB(), DSET_cor(), EDIT_main(), Fourier_Filter_Driver(), HISTO_main(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), NUD_finalize_dset_CB(), NUD_quit_CB(), PC_read_opts(), PLUTO_4D_to_nothing(), POWER_main(), PRIC_main(), REORDER_main(), SCAT_main(), THD_autonudge(), THD_load_tcat(), THD_makemask(), THD_warp3D(), THD_zeropad(), TT_retrieve_atlas_big(), UC_read_opts(), VL_command_line(), VOLREG_main(), write_results(), and ZPAD_main().

#define DSET_unload_one ds,
iv       THD_purge_one_brick( (ds)->dblk , (iv) )
 

Unload sub-brick iv in dataset ds from memory.

Only does something if the dataset is malloc()-ed, not mmap()-ed, and not locked in memory

Definition at line 2660 of file 3ddata.h.

Referenced by main(), PC_read_opts(), THD_warp3D(), THD_write_minc(), THD_zeropad(), UC_read_opts(), and VOLREG_main().

#define DSET_unlock ds       DBLK_unlock((ds)->dblk)
 

Unlock dataset ds (so it can be purged)

Definition at line 2691 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), adwarp_refashion_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_refashion_dataset(), DRAW_done_CB(), DRAW_quit_CB(), DRAW_saveas_finalize_CB(), NUD_finalize_dset_CB(), NUD_quit_CB(), r_save_dataset_as(), and RT_tell_afni_one().

#define DSET_VALID_BSTAT dset,
ii   
 

Value:

( ISVALID_3DIM_DATASET((dset))     &&           \
    ISVALID_STATISTIC((dset)->stats) &&           \
    (ii) < (dset)->stats->nbstat     &&           \
    ISVALID_BSTAT( (dset)->stats->bstat[(ii)] ) )
Determine if the ii-th volume of dataset dset has a valid brick statistic. Brick statistics are just the min and max values in the volume.

Definition at line 2602 of file 3ddata.h.

Referenced by AFNI_autorange_label(), AFNI_range_label(), RCREND_autorange_label(), RCREND_range_label(), REND_autorange_label(), and REND_range_label().

#define DSET_VERSION_COMPARE v1,
v2       strcmp(v1,v2)
 

Definition at line 16 of file 3ddata.h.

#define DSET_VERSION_LATEST   "1996-07-10"
 

yyyy-mm-dd *

Definition at line 15 of file 3ddata.h.

#define DSET_write ds   
 

Value:

( THD_load_statistics( (ds) ) ,                    \
                          THD_write_3dim_dataset( NULL,NULL , (ds),True ) )
Write dataset ds to disk.

Also loads the sub-brick statistics

Definition at line 2672 of file 3ddata.h.

Referenced by applyMask(), basis_write_iresp(), basis_write_sresp(), CLUST_main(), do_xrestore_stuff(), DRAW_done_CB(), DRAW_save_CB(), DRAW_saveas_finalize_CB(), Fourier_Filter_Driver(), main(), NUD_doall_CB(), PERMTEST_main(), process_NIML_Node_ROI(), r_save_dataset_as(), saveMask(), THRESH_main(), write_bucket_data(), write_output(), and write_results().

#define DSET_write_header ds       THD_write_3dim_dataset( NULL,NULL , (ds),False )
 

Write only the dataset header to disk, for dataset ds

Definition at line 2677 of file 3ddata.h.

Referenced by main(), NOTES_save_CB(), and TAG_save_CB().

#define DSET_WRITEABLE ds   
 

Value:

( ISVALID_DSET(ds)          &&  \
   ISVALID_DBLK((ds)->dblk)  &&  \
   (ds)->warp_parent != NULL &&  \
   !DSET_IS_MINC(ds)         &&  \
   !DSET_IS_ANALYZE(ds)        )
Determine if AFNI is allowed to over-write dataset ds

Definition at line 2210 of file 3ddata.h.

Referenced by AFNI_do_many_writes(), AFNI_setup_viewing(), AFNI_write_dataset_CB(), and AFNI_write_many_dataset_CB().

#define DSET_XORG ds       ((ds)->daxes->xxorg)
 

Return grid origin along x-axis of dataset ds

Definition at line 2404 of file 3ddata.h.

Referenced by main(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_MarchingCubesSurface(), SUMA_VolParFromDset(), THD_autonudge(), THD_dicomm_to_surefit(), THD_surefit_to_dicomm(), and THD_write_1D().

#define DSET_XXMAX ds       ((ds)->daxes->xxmax)
 

Return largest x-coordinate of grid for dataset ds

Definition at line 2420 of file 3ddata.h.

Referenced by process_NIML_Node_ROI(), and SUMA_make_vnlist().

#define DSET_XXMIN ds       ((ds)->daxes->xxmin)
 

Return smallest x-coordinate of grid for dataset ds

Definition at line 2416 of file 3ddata.h.

Referenced by process_NIML_Node_ROI(), and SUMA_make_vnlist().

#define DSET_YORG ds       ((ds)->daxes->yyorg)
 

Return grid origin along y-axis of dataset ds

Definition at line 2408 of file 3ddata.h.

Referenced by main(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_MarchingCubesSurface(), SUMA_VolParFromDset(), THD_autonudge(), THD_dicomm_to_surefit(), THD_surefit_to_dicomm(), and THD_write_1D().

#define DSET_YYMAX ds       ((ds)->daxes->yymax)
 

Return largest y-coordinate of grid for dataset ds

Definition at line 2428 of file 3ddata.h.

Referenced by process_NIML_Node_ROI(), and SUMA_make_vnlist().

#define DSET_YYMIN ds       ((ds)->daxes->yymin)
 

Return smallest y-coordinate of grid for dataset ds

Definition at line 2424 of file 3ddata.h.

Referenced by process_NIML_Node_ROI(), and SUMA_make_vnlist().

#define DSET_ZORG ds       ((ds)->daxes->zzorg)
 

Return grid origin along y-axis of dataset ds

Definition at line 2412 of file 3ddata.h.

Referenced by main(), set_3dmm_bounds(), SUMA_ConvexHullSurface(), SUMA_MarchingCubesSurface(), SUMA_VolParFromDset(), THD_autonudge(), THD_dicomm_to_surefit(), THD_surefit_to_dicomm(), and THD_write_1D().

#define DSET_ZZMAX ds       ((ds)->daxes->zzmax)
 

Return largest z-coordinate of grid for dataset ds

Definition at line 2436 of file 3ddata.h.

Referenced by process_NIML_Node_ROI(), and SUMA_make_vnlist().

#define DSET_ZZMIN ds       ((ds)->daxes->zzmin)
 

Return smallest z-coordinate of grid for dataset ds

Definition at line 2432 of file 3ddata.h.

Referenced by process_NIML_Node_ROI(), and SUMA_make_vnlist().

#define DUMP_LMAP m   
 

Value:

( printf("THD_linear_mapping:\n") ,                                     \
  printf("   mfor = %8.4f %8.4f %8.4f\n",                               \
         (m).mfor.mat[0][0], (m).mfor.mat[0][1], (m).mfor.mat[0][2] ) , \
  printf("          %8.4f %8.4f %8.4f\n",                               \
         (m).mfor.mat[1][0], (m).mfor.mat[1][1], (m).mfor.mat[1][2] ) , \
  printf("          %8.4f %8.4f %8.4f\n",                               \
         (m).mfor.mat[2][0], (m).mfor.mat[2][1], (m).mfor.mat[2][2] ) , \
  printf("   mbac = %8.4f %8.4f %8.4f\n",                               \
         (m).mbac.mat[0][0], (m).mbac.mat[0][1], (m).mbac.mat[0][2] ) , \
  printf("          %8.4f %8.4f %8.4f\n",                               \
         (m).mbac.mat[1][0], (m).mbac.mat[1][1], (m).mbac.mat[1][2] ) , \
  printf("          %8.4f %8.4f %8.4f\n",                               \
         (m).mbac.mat[2][0], (m).mbac.mat[2][1], (m).mbac.mat[2][2] ) , \
  printf("   bvec = %8.4f %8.4f %8.4f\n",                               \
         (m).bvec.xyz[0] , (m).bvec.xyz[1] , (m).bvec.xyz[2] ) ,        \
  printf("   svec = %8.4f %8.4f %8.4f\n",                               \
         (m).svec.xyz[0] , (m).svec.xyz[1] , (m).svec.xyz[2] ) ,        \
  printf("   bot  = %8.4f %8.4f %8.4f\n",                               \
         (m).bot.xyz[0]  , (m).bot.xyz[1]  , (m).bot.xyz[2] )  ,        \
  printf("   top  = %8.4f %8.4f %8.4f\n\n",                             \
         (m).top.xyz[0]  , (m).top.xyz[1]  , (m).top.xyz[2] ) )
Debugging printout of a THD_linear_mapping struct.

Definition at line 524 of file 3ddata.h.

Referenced by AFNI_init_warp(), AFNI_make_warp(), and THD_init_session().

#define DUMP_T12_MAP t12,
xx,
yy,
zz   
 

Value:

(  printf("\n--- submap " # xx # yy # zz "\n" ) , \
    DUMP_LMAP( (t12).warp[W_ ## xx ## yy ## zz] )    )
Debug printout for 1 piece of a Talairach warp.

Definition at line 798 of file 3ddata.h.

#define DUMP_T12_WARP t12   
 

Value:

( printf("\n12 region Talairach warp:") ,                 \
   DUMP_T12_MAP((t12),R,A,S) , DUMP_T12_MAP((t12),L,A,S) , \
   DUMP_T12_MAP((t12),R,M,S) , DUMP_T12_MAP((t12),L,M,S) , \
   DUMP_T12_MAP((t12),R,P,S) , DUMP_T12_MAP((t12),L,P,S) , \
   DUMP_T12_MAP((t12),R,A,I) , DUMP_T12_MAP((t12),L,A,I) , \
   DUMP_T12_MAP((t12),R,M,I) , DUMP_T12_MAP((t12),L,M,I) , \
   DUMP_T12_MAP((t12),R,P,I) , DUMP_T12_MAP((t12),L,P,I)    )
Debug printout for all 12 pieces of a Talairach warp.

Definition at line 804 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define DUPLICATE_DSETS ds,
es   
 

Value:

( (ds) != (es) &&             \
     (ds) != NULL &&             \
     (es) != NULL && EQUIV_IDCODES((ds)->idcode,(es)->idcode) )
Check if 2 AFNI dataset pointers are different but have the same ID codes.

Definition at line 1483 of file 3ddata.h.

Referenced by THD_check_idcodes().

#define EQUIV_DATAXES cax,
dax   
 

Value:

( ISVALID_DATAXES((cax))                      && \
    ISVALID_DATAXES((dax))                      && \
    (cax)->nxx == (dax)->nxx                    && \
    (cax)->nyy == (dax)->nyy                    && \
    (cax)->nzz == (dax)->nzz                    && \
    fabs( (cax)->xxorg - (dax)->xxorg ) < 0.01  && \
    fabs( (cax)->yyorg - (dax)->yyorg ) < 0.01  && \
    fabs( (cax)->zzorg - (dax)->zzorg ) < 0.01  && \
    fabs( (cax)->xxdel - (dax)->xxdel ) < 0.001 && \
    fabs( (cax)->yydel - (dax)->yydel ) < 0.001 && \
    fabs( (cax)->zzdel - (dax)->zzdel ) < 0.001 && \
    (cax)->xxorient == (dax)->xxorient          && \
    (cax)->yyorient == (dax)->yyorient          && \
    (cax)->zzorient == (dax)->zzorient    )
Check if two THD_dataxes are essential equivalent.

Definition at line 1330 of file 3ddata.h.

Referenced by AFNI_setup_viewing(), AFNI_vnlist_func_overlay(), DRAW_choose_CB(), DRAW_finalize_dset_CB(), DRAW_receiver(), main(), process_NIML_Node_ROI(), RCREND_reload_func_dset(), THD_open_tcat(), and verify_inputs().

#define EQUIV_DSETS ds,
es   
 

Value:

( (ds)==(es) ||         \
     ((ds)!=NULL && (es)!=NULL && EQUIV_IDCODES((ds)->idcode,(es)->idcode)) )
Check if 2 AFNI dataset pointers point to the same dataset struct.

Definition at line 1477 of file 3ddata.h.

Referenced by AFNI_brick_to_mri(), AFNI_process_plugout(), AFNI_range_setter(), BFIT_prepare_dataset(), CORREL_main(), HISTO_main(), RCREND_xhair_recv(), REND_xhair_recv(), RT_tell_afni_one(), SCAT_main(), and TAG_check_copyset().

#define EQUIV_IDCODES id,
ie       (strncmp((id).str,(ie).str,MCW_IDSIZE) == 0)
 

Check if 2 ID code strings are equal.

Definition at line 1473 of file 3ddata.h.

Referenced by main(), PLUG_choose_dataset_CB(), RCREND_choose_CB(), RCREND_save_state(), RCREND_state_to_widgets(), REND_choose_CB(), REND_save_state(), REND_state_to_widgets(), and THD_dset_in_session().

#define FAIL   -1
 

Definition at line 109 of file 3ddata.h.

Referenced by disp_opts_data(), init_options(), main(), r_fill_resampled_data_brick(), resam_str2mode(), sync_master_opts(), THD_read_all_atr(), THD_write_atr(), usage(), and write_results().

#define FILECODE_TO_PREFIX fc,
pr   
 

Value:

do{ char *qq , *ff , *pp ;                                          \
      if( strstr((fc),"+") == NULL ){                                 \
         (pr)[0] = '\0' ;                                             \
      } else {                                                        \
         for( qq=fc+strlen((fc)) ; *qq != '+' ; qq-- ) ;              \
         for( ff=(fc) , (pp)=(pr) ; ff < qq ; ff++,pp++ ) *pp = *ff ; \
         *pp = '\0' ; } break ; } while(1)
Extract the prefix from a filecode (prefix+view).

  • If there is no '+', puts an empty string into pr
  • Otherwise, scans backward from end to find last '+'; everything before that is the prefix
  • Space for pr must be allocated beforehand

Definition at line 970 of file 3ddata.h.

#define FILENAME_TO_PREFIX fn,
pr   
 

Value:

do{ int ii ;                                \
      for( ii=strlen((fn)) ; ii >= 0 ; ii-- ) \
         if( (fn)[ii] == '/' ) break ;        \
      FILECODE_TO_PREFIX( (fn)+(ii+1) , (pr) ) ; break ; } while(1)
Extract the prefix from a filename.

Definition at line 991 of file 3ddata.h.

Referenced by do_xrestore_stuff(), T3D_anatomy_parent_CB(), T3D_geometry_parent_CB(), THD_datablock_from_atr(), THD_init_alldir_datablocks(), THD_init_one_datablock(), and THD_init_prefix_datablocks().

#define FIMTHR   0
 

Definition at line 1778 of file 3ddata.h.

#define FIND_IDCODE   2
 

Definition at line 2929 of file 3ddata.h.

Referenced by AFNI_drive_purge_memory(), AFNI_drive_switch_anatomy(), AFNI_drive_switch_function(), AFNI_make_descendants_old(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), DRAW_finalize_dset_CB(), DSET_in_global_session(), PLUTO_dset_finder(), PLUTO_find_dset(), RENAME_main(), THD_dset_in_session(), and THD_reconcile_parents().

#define FIND_NAME   1
 

Definition at line 2928 of file 3ddata.h.

Referenced by AFNI_make_descendants_old(), THD_dset_in_session(), and THD_reconcile_parents().

#define FIND_PREFIX   3
 

Definition at line 2930 of file 3ddata.h.

Referenced by AFNI_drive_purge_memory(), AFNI_drive_switch_anatomy(), AFNI_drive_switch_function(), AFNI_fimmer_compute(), AFNI_rescan_session_NEW(), PLUTO_prefix_ok(), process_NIML_Node_ROI(), and THD_dset_in_session().

#define FIRST_3DIM_TYPE   0
 

Definition at line 1534 of file 3ddata.h.

Referenced by EDIT_dset_items(), main(), T3D_create_widgets(), and THD_3dim_from_block().

#define FIRST_ANAT_TYPE   0
 

Definition at line 1900 of file 3ddata.h.

Referenced by main(), Syntax(), T3D_create_widgets(), and T3D_initialize_user_data().

#define FIRST_ATR_TYPE   0
 

Definition at line 430 of file 3ddata.h.

Referenced by THD_read_all_atr().

#define FIRST_FUNC_TYPE   0
 

Definition at line 1709 of file 3ddata.h.

Referenced by main(), Syntax(), T3D_create_widgets(), and T3D_initialize_user_data().

#define FIRST_MAPPING_TYPE   0
 

Definition at line 485 of file 3ddata.h.

#define FIRST_ORIENT_TYPE   0
 

Definition at line 1223 of file 3ddata.h.

Referenced by EDIT_dset_items(), and T3D_create_widgets().

#define FIRST_RESAM_TYPE   0
 

Definition at line 762 of file 3ddata.h.

Referenced by AFNI_load_defaults(), AFNI_write_dataset_CB(), and resam_str2mode().

#define FIRST_STAT_TYPE   2
 

Definition at line 1712 of file 3ddata.h.

#define FIRST_VIEW_TYPE   0
 

Definition at line 1561 of file 3ddata.h.

Referenced by AFNI_andersonville(), AFNI_choose_dataset_CB(), AFNI_finalize_dataset_CB(), AFNI_mark_for_death(), AFNI_purge_dsets(), BUCK_read_opts(), EDIT_dset_items(), main(), RENAME_main(), T3D_create_widgets(), T3D_initialize_user_data(), TCAT_read_opts(), THD_check_idcodes(), THD_dataset_headname(), THD_dset_in_session(), THD_init_diskptr_names(), THD_is_dataset(), and THD_reconcile_parents().

#define FIRST_WARP_TYPE   0
 

Definition at line 741 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define FREE_3DARR name   
 

Value:

if( (name) != NULL ){      \
     myXtFree( (name)->ar ) ; \
     myXtFree( (name) ) ; }
Free the AFNI dataset array (but don't kill the datasets).

This would be used after the dataset pointers have been moved someplace else (e.g., into the THD_session structure).

Definition at line 2798 of file 3ddata.h.

Referenced by THD_array_3dim_from_block(), and THD_init_session().

#define FREE_DBARR name   
 

Value:

if( (name) != NULL ){      \
     myXtFree( (name)->ar ) ; \
     myXtFree( (name) ) ; }
Free the space used by a THD_datablock_array (but not the datablocks themselves).

Definition at line 1186 of file 3ddata.h.

Referenced by THD_init_alldir_datablocks(), and THD_init_session().

#define FREE_XTARR name   
 

Value:

if( (name) != NULL ){      \
     myXtFree( (name)->ar ) ; \
     myXtFree( (name)->ic ) ; \
     myXtFree( (name) ) ;     \
     (name) = NULL ; }
Free a dynamic XtPointer array.

But not what the pointers point to - that is a completely separate matter.

Definition at line 263 of file 3ddata.h.

Referenced by AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), THD_fetch_many_datasets(), and THD_init_session().

#define FUNC_0D   0
 

MCW_function_list possible func_code

Definition at line 154 of file 3ddata.h.

#define FUNC_1D   1
 

MCW_function_list possible func_code

Definition at line 156 of file 3ddata.h.

#define FUNC_2D   2
 

MCW_function_list possible func_code

Definition at line 158 of file 3ddata.h.

#define FUNC_3D   3
 

MCW_function_list possible func_code

Definition at line 160 of file 3ddata.h.

#define FUNC_ALL_MASK
 

Value:

Definition at line 1715 of file 3ddata.h.

Referenced by CORREL_init(), and PLUGIN_init().

#define FUNC_BN_DESCRIPTOR   "Binomial Distribution"
 

Definition at line 1673 of file 3ddata.h.

#define FUNC_BN_LABEL   "Bino"
 

Definition at line 1672 of file 3ddata.h.

#define FUNC_BN_MASK   (1 << FUNC_BN_TYPE)
 

Definition at line 1674 of file 3ddata.h.

#define FUNC_BN_PREFIX   "fibn"
 

Definition at line 1668 of file 3ddata.h.

#define FUNC_BN_SCALE_BYTE   1
 

Definition at line 1671 of file 3ddata.h.

#define FUNC_BN_SCALE_SHORT   100
 

Definition at line 1670 of file 3ddata.h.

#define FUNC_BN_STR   "Inten+Binom"
 

Definition at line 1667 of file 3ddata.h.

#define FUNC_BN_TOP   100.0
 

Definition at line 1669 of file 3ddata.h.

#define FUNC_BN_TYPE   8
 

Definition at line 1666 of file 3ddata.h.

#define FUNC_BT_DESCRIPTOR   "Beta Distribution"
 

Definition at line 1662 of file 3ddata.h.

#define FUNC_BT_LABEL   "Beta"
 

Definition at line 1661 of file 3ddata.h.

#define FUNC_BT_MASK   (1 << FUNC_BT_TYPE)
 

Definition at line 1663 of file 3ddata.h.

#define FUNC_BT_PREFIX   "fibt"
 

Definition at line 1657 of file 3ddata.h.

#define FUNC_BT_SCALE_BYTE   100
 

Definition at line 1660 of file 3ddata.h.

#define FUNC_BT_SCALE_SHORT   10000
 

Definition at line 1659 of file 3ddata.h.

#define FUNC_BT_STR   "Inten+Beta"
 

Definition at line 1656 of file 3ddata.h.

#define FUNC_BT_TOP   1.0
 

Definition at line 1658 of file 3ddata.h.

#define FUNC_BT_TYPE   7
 

Definition at line 1655 of file 3ddata.h.

#define FUNC_BUCK_DESCRIPTOR   "Function Bucket"
 

Definition at line 1706 of file 3ddata.h.

#define FUNC_BUCK_LABEL   "Buck"
 

Definition at line 1705 of file 3ddata.h.

#define FUNC_BUCK_MASK   (1 << FUNC_BUCK_TYPE)
 

Definition at line 1707 of file 3ddata.h.

#define FUNC_BUCK_PREFIX   "fbuc"
 

Definition at line 1701 of file 3ddata.h.

#define FUNC_BUCK_SCALE_BYTE   1
 

Definition at line 1704 of file 3ddata.h.

#define FUNC_BUCK_SCALE_SHORT   1
 

Definition at line 1703 of file 3ddata.h.

#define FUNC_BUCK_STR   "Func-Bucket"
 

Definition at line 1700 of file 3ddata.h.

#define FUNC_BUCK_TOP   1.0
 

Definition at line 1702 of file 3ddata.h.

#define FUNC_BUCK_TYPE   11
 

Definition at line 1699 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), do_xrestore_stuff(), form_clusters(), main(), MAKER_4D_to_typed_fbuc(), output_results(), process_NIML_Node_ROI(), s2v_nodes2volume(), THD_open_nifti(), THD_setup_mastery(), write_bucket(), and write_bucket_data().

#define FUNC_COR_DESCRIPTOR   "Correlation Coefficient"
 

Definition at line 1608 of file 3ddata.h.

#define FUNC_COR_LABEL   "Corr"
 

Definition at line 1607 of file 3ddata.h.

#define FUNC_COR_MASK   (1 << FUNC_COR_TYPE)
 

Definition at line 1609 of file 3ddata.h.

#define FUNC_COR_PREFIX   "fico"
 

Definition at line 1603 of file 3ddata.h.

#define FUNC_COR_SCALE_BYTE   100
 

Definition at line 1606 of file 3ddata.h.

#define FUNC_COR_SCALE_SHORT   10000
 

Definition at line 1605 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), fim3d_fimmer_compute(), main(), and RT_fim_recurse().

#define FUNC_COR_STR   "Inten+Cor"
 

Definition at line 1602 of file 3ddata.h.

#define FUNC_COR_TOP   1.0
 

Definition at line 1604 of file 3ddata.h.

#define FUNC_COR_TYPE   2
 

Definition at line 1601 of file 3ddata.h.

#define FUNC_CT_DESCRIPTOR   "Chi-Squared statistic"
 

Definition at line 1651 of file 3ddata.h.

#define FUNC_CT_LABEL   "ChiS"
 

Definition at line 1650 of file 3ddata.h.

#define FUNC_CT_MASK   (1 << FUNC_CT_TYPE)
 

Definition at line 1652 of file 3ddata.h.

#define FUNC_CT_PREFIX   "fict"
 

Definition at line 1646 of file 3ddata.h.

#define FUNC_CT_SCALE_BYTE   1
 

Definition at line 1649 of file 3ddata.h.

#define FUNC_CT_SCALE_SHORT   100
 

Definition at line 1648 of file 3ddata.h.

Referenced by write_afni_fict().

#define FUNC_CT_STR   "Inten+ChiSq"
 

Definition at line 1645 of file 3ddata.h.

#define FUNC_CT_TOP   100.0
 

Definition at line 1647 of file 3ddata.h.

#define FUNC_CT_TYPE   6
 

Definition at line 1644 of file 3ddata.h.

#define FUNC_FIM   71
 

MCW_function_list possible func_code

Definition at line 163 of file 3ddata.h.

Referenced by AFNI_register_fimfunc().

#define FUNC_FIM_DESCRIPTOR   "Functional Intensity"
 

Definition at line 1582 of file 3ddata.h.

#define FUNC_FIM_LABEL   "fim"
 

Definition at line 1581 of file 3ddata.h.

#define FUNC_FIM_MASK   (1 << FUNC_FIM_TYPE)
 

Definition at line 1583 of file 3ddata.h.

Referenced by CORREL_init(), and PLUGIN_init().

#define FUNC_FIM_PREFIX   "fim"
 

Definition at line 1580 of file 3ddata.h.

#define FUNC_FIM_STR   "Intensity"
 

Definition at line 1579 of file 3ddata.h.

#define FUNC_FIM_TYPE   0
 

Definition at line 1578 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), AFNI_setup_viewing(), allocate_pieces(), applyMask(), COPY_main(), count_volumes_and_files(), do_xrestore_stuff(), DRAW_copy_dset(), DUMP_main(), EDIT_main(), get_inputs(), get_options(), init_maxima_s(), main(), MAKER_4D_to_typed_fim(), saveMask(), SUMA_FormAfnidset(), THD_open_analyze(), THD_open_ctfsam(), THD_open_nifti(), THD_open_tcat(), THRESH_main(), write_afni_data(), write_bucket_data(), and write_results().

#define FUNC_FT_DESCRIPTOR   "Fisher F-statistic"
 

Definition at line 1629 of file 3ddata.h.

#define FUNC_FT_LABEL   "F-t "
 

Definition at line 1628 of file 3ddata.h.

#define FUNC_FT_MASK   (1 << FUNC_FT_TYPE)
 

Definition at line 1630 of file 3ddata.h.

#define FUNC_FT_PREFIX   "fift"
 

Definition at line 1624 of file 3ddata.h.

#define FUNC_FT_SCALE_BYTE   1
 

Definition at line 1627 of file 3ddata.h.

#define FUNC_FT_SCALE_SHORT   100
 

Definition at line 1626 of file 3ddata.h.

Referenced by write_afni_data().

#define FUNC_FT_STR   "Inten+Ftest"
 

Definition at line 1623 of file 3ddata.h.

#define FUNC_FT_TOP   100.0
 

Definition at line 1625 of file 3ddata.h.

#define FUNC_FT_TYPE   4
 

Definition at line 1622 of file 3ddata.h.

#define FUNC_GT_DESCRIPTOR   "Gamma Distribution"
 

Definition at line 1684 of file 3ddata.h.

#define FUNC_GT_LABEL   "Gam "
 

Definition at line 1683 of file 3ddata.h.

#define FUNC_GT_MASK   (1 << FUNC_GT_TYPE)
 

Definition at line 1685 of file 3ddata.h.

#define FUNC_GT_PREFIX   "figt"
 

Definition at line 1679 of file 3ddata.h.

#define FUNC_GT_SCALE_BYTE   10
 

Definition at line 1682 of file 3ddata.h.

#define FUNC_GT_SCALE_SHORT   1000
 

Definition at line 1681 of file 3ddata.h.

#define FUNC_GT_STR   "Inten+Gamma"
 

Definition at line 1678 of file 3ddata.h.

#define FUNC_GT_TOP   10.0
 

Definition at line 1680 of file 3ddata.h.

#define FUNC_GT_TYPE   9
 

Definition at line 1677 of file 3ddata.h.

#define FUNC_HAVE_FIM ftyp   
 

Value:

((ftyp) >= 0 && \
                              (ftyp) <= LAST_FUNC_TYPE && FUNC_ival_fim[(ftyp)] >= 0)

Definition at line 1782 of file 3ddata.h.

#define FUNC_HAVE_PVAL   FUNC_IS_STAT
 

Definition at line 1789 of file 3ddata.h.

Referenced by AFNI_thr_scale_drag_CB().

#define FUNC_HAVE_THR ftyp   
 

Value:

((ftyp) >= 0 && \
                              (ftyp) <= LAST_FUNC_TYPE && FUNC_ival_thr[(ftyp)] >= 0)

Definition at line 1785 of file 3ddata.h.

Referenced by EDIT_main(), main(), and T3D_save_file_CB().

#define FUNC_IS_STAT ftyp       ((ftyp) >= FIRST_STAT_TYPE && (ftyp) <= LAST_STAT_TYPE)
 

Definition at line 1788 of file 3ddata.h.

Referenced by EDIT_one_dataset(), EDIT_zscore_vol(), main(), process_dataset(), Syntax(), THD_dataset_info(), THD_set_dataset_attributes(), and THD_store_datablock_stataux().

#define FUNC_PAIR_PREFIX   "fith"
 

Definition at line 1589 of file 3ddata.h.

#define FUNC_PAIR_STR   "Inten+Thr"
 

Definition at line 1588 of file 3ddata.h.

#define FUNC_PAIR_TYPE   1
 

old PAIR type retained for compatibility *

Definition at line 1587 of file 3ddata.h.

#define FUNC_PT_DESCRIPTOR   "Poisson Distribution"
 

Definition at line 1695 of file 3ddata.h.

#define FUNC_PT_LABEL   "Pois"
 

Definition at line 1694 of file 3ddata.h.

#define FUNC_PT_MASK   (1 << FUNC_PT_TYPE)
 

Definition at line 1696 of file 3ddata.h.

#define FUNC_PT_PREFIX   "fipt"
 

Definition at line 1690 of file 3ddata.h.

#define FUNC_PT_SCALE_BYTE   1
 

Definition at line 1693 of file 3ddata.h.

#define FUNC_PT_SCALE_SHORT   100
 

Definition at line 1692 of file 3ddata.h.

#define FUNC_PT_STR   "Inten+Poisson"
 

Definition at line 1689 of file 3ddata.h.

#define FUNC_PT_TOP   100.0
 

Definition at line 1691 of file 3ddata.h.

#define FUNC_PT_TYPE   10
 

Definition at line 1688 of file 3ddata.h.

#define FUNC_THR_DESCRIPTOR   "Old style threshold"
 

Definition at line 1598 of file 3ddata.h.

#define FUNC_THR_LABEL   "Thr "
 

Definition at line 1597 of file 3ddata.h.

#define FUNC_THR_MASK   (1 << FUNC_PAIR_TYPE)
 

Definition at line 1599 of file 3ddata.h.

#define FUNC_THR_PREFIX   FUNC_PAIR_PREFIX
 

Definition at line 1593 of file 3ddata.h.

#define FUNC_THR_SCALE_BYTE   100
 

Definition at line 1596 of file 3ddata.h.

#define FUNC_THR_SCALE_SHORT   10000
 

Definition at line 1595 of file 3ddata.h.

Referenced by MAKER_4D_to_typed_fith(), and write_afni_data().

#define FUNC_THR_STR   FUNC_PAIR_STR
 

Definition at line 1592 of file 3ddata.h.

#define FUNC_THR_TOP   1.0
 

Definition at line 1594 of file 3ddata.h.

#define FUNC_THR_TYPE   FUNC_PAIR_TYPE
 

Definition at line 1591 of file 3ddata.h.

Referenced by allocate_pieces(), count_volumes_and_files(), do_xrestore_stuff(), get_inputs(), main(), MAKER_4D_to_typed_fith(), output_results(), write_afni_data(), and write_bucket_data().

#define FUNC_TT_DESCRIPTOR   "Student t-statistic"
 

Definition at line 1618 of file 3ddata.h.

#define FUNC_TT_LABEL   "T-t "
 

Definition at line 1617 of file 3ddata.h.

#define FUNC_TT_MASK   (1 << FUNC_TT_TYPE)
 

Definition at line 1619 of file 3ddata.h.

#define FUNC_TT_PREFIX   "fitt"
 

Definition at line 1613 of file 3ddata.h.

#define FUNC_TT_SCALE_BYTE   10
 

Definition at line 1616 of file 3ddata.h.

#define FUNC_TT_SCALE_SHORT   1000
 

Definition at line 1615 of file 3ddata.h.

Referenced by main(), and write_afni_data().

#define FUNC_TT_STR   "Inten+Ttest"
 

Definition at line 1612 of file 3ddata.h.

#define FUNC_TT_TOP   10.0
 

Definition at line 1614 of file 3ddata.h.

#define FUNC_TT_TYPE   3
 

Definition at line 1611 of file 3ddata.h.

#define FUNC_ZT_DESCRIPTOR   "Normal (Gaussian) Z"
 

Definition at line 1640 of file 3ddata.h.

#define FUNC_ZT_LABEL   "Z-t "
 

Definition at line 1639 of file 3ddata.h.

#define FUNC_ZT_MASK   (1 << FUNC_ZT_TYPE)
 

Definition at line 1641 of file 3ddata.h.

#define FUNC_ZT_PREFIX   "fizt"
 

Definition at line 1635 of file 3ddata.h.

#define FUNC_ZT_SCALE_BYTE   10
 

Definition at line 1638 of file 3ddata.h.

#define FUNC_ZT_SCALE_SHORT   1000
 

Definition at line 1637 of file 3ddata.h.

Referenced by EDIT_one_dataset(), EDIT_zscore_vol(), PERMTEST_compute(), PERMTEST_main(), and write_afni_fizt().

#define FUNC_ZT_STR   "Inten+Ztest"
 

Definition at line 1634 of file 3ddata.h.

#define FUNC_ZT_TOP   10.0
 

Definition at line 1636 of file 3ddata.h.

#define FUNC_ZT_TYPE   5
 

Definition at line 1633 of file 3ddata.h.

#define GEN_ANAT_STR   "3DIM_GEN_ANAT"
 

Definition at line 1529 of file 3ddata.h.

#define GEN_ANAT_TYPE   2
 

Definition at line 1528 of file 3ddata.h.

Referenced by AFNI_read_images().

#define GEN_FUNC_STR   "3DIM_GEN_FUNC"
 

Definition at line 1532 of file 3ddata.h.

#define GEN_FUNC_TYPE   3
 

Definition at line 1531 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), check_one_output_file(), check_output_file(), fim3d_fimmer_compute(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), PERMTEST_main(), RT_fim_recurse(), THRESH_main(), write_afni_data(), write_afni_fict(), and write_afni_fizt().

#define HAS_TIMEAXIS ds       ( DSET_NUM_TIMES(ds) > 1 )
 

Check if have a 3D+time dataset.

Definition at line 2361 of file 3ddata.h.

Referenced by AFNI_time_index_CB(), and THD_write_1D().

#define HEAD_ANAT_STR   "3DIM_HEAD_ANAT"
 

Definition at line 1523 of file 3ddata.h.

#define HEAD_ANAT_TYPE   0
 

Definition at line 1522 of file 3ddata.h.

Referenced by AFNI_init_warp(), AFNI_read_inputs(), applyMask(), BUCK_read_opts(), COPY_main(), DRAW_copy_dset(), EDIT_empty_copy(), EDIT_wod_copy(), main(), RT_start_dataset(), SUMA_BrainVoyager_Read_vmr(), SUMA_OpenDX_Read_CruiseVolHead(), T3D_initialize_user_data(), T3D_save_file_CB(), THD_open_1D(), THD_open_3D(), THD_open_analyze(), THD_open_ctfmri(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), and ZPAD_main().

#define HEAD_FUNC_STR   "3DIM_HEAD_FUNC"
 

Definition at line 1526 of file 3ddata.h.

#define HEAD_FUNC_TYPE   1
 

Definition at line 1525 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), BUCK_read_opts(), check_one_output_file(), check_output_file(), COPY_main(), do_xrestore_stuff(), DRAW_copy_dset(), fim3d_fimmer_compute(), form_clusters(), init_maxima_s(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), process_NIML_Node_ROI(), RT_fim_recurse(), s2v_nodes2volume(), saveMask(), SUMA_FormAfnidset(), T3D_initialize_user_data(), THD_open_analyze(), THD_open_ctfsam(), THD_open_nifti(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), write_results(), and ZPAD_main().

#define IC_DSET   44301
 

Definition at line 205 of file 3ddata.h.

Referenced by AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), and THD_fetch_many_datasets().

#define IC_FLIM   55402
 

Definition at line 206 of file 3ddata.h.

Referenced by AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), and THD_fetch_many_datasets().

#define IDENTITY_WARP
 

Value:

( tempA_warp.rig_bod.type       = WARP_AFFINE_TYPE ,                 \
     tempA_warp.rig_bod.resam_type = RESAM_NN_TYPE ,                    \
     tempA_warp.rig_bod.warp.type  = MAPPING_LINEAR_TYPE ,              \
     LOAD_DIAG_MAT( tempA_warp.rig_bod.warp.mfor ,     1,    1,    1 ) ,\
     LOAD_DIAG_MAT( tempA_warp.rig_bod.warp.mbac ,     1,    1,    1 ) ,\
     LOAD_FVEC3(    tempA_warp.rig_bod.warp.bvec ,     0,    0,    0 ) ,\
     LOAD_FVEC3(    tempA_warp.rig_bod.warp.svec ,     0,    0,    0 ) ,\
     LOAD_FVEC3(    tempA_warp.rig_bod.warp.bot  , -9999,-9999,-9999 ) ,\
     LOAD_FVEC3(    tempA_warp.rig_bod.warp.top  ,  9999, 9999, 9999 ) ,\
     tempA_warp )
Return value is an affine warp set to the identity transformation.

Definition at line 844 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_dataset_slice(), AFNI_follower_dataset(), DUP_main(), duplicate_dataset(), EDIT_wod_copy(), main(), r_fill_resampled_data_brick(), and THD_copy_dset_subs().

#define ILLEGAL_TYPE   -666
 

General "type code" for invalid data.

Various things are labeled with non-negative type codes (e.g., statistics types). Negative type codes indicate something is not valid.

Definition at line 118 of file 3ddata.h.

#define IMARK_ACPM   1
 

Definition at line 609 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_ACSE   0
 

Definition at line 608 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MANT   0
 

Definition at line 663 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MINF   3
 

Definition at line 666 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MLEF   4
 

Definition at line 667 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MPOS   1
 

Definition at line 664 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MRIG   5
 

Definition at line 668 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MSA1   3
 

Definition at line 611 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MSA2   4
 

Definition at line 612 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_MSUP   2
 

Definition at line 665 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define IMARK_PCIE   2
 

Definition at line 610 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define INC_3DARR   8
 

Definition at line 2767 of file 3ddata.h.

#define INC_DBARR   8
 

Definition at line 1161 of file 3ddata.h.

#define INC_SARR   64
 

Definition at line 292 of file 3ddata.h.

#define INC_XTARR   8
 

Increment for extending XtPointer_array allocation

Definition at line 219 of file 3ddata.h.

#define INIT_3DARR name   
 

Value:

( (name) = XtNew(THD_3dim_dataset_array) ,\
     (name)->num = (name)->nall = 0 ,     \
     (name)->ar  = NULL )
Initialize a new AFNI dataset array into variable "name".

You should declare "THD_3dim_dataset_array *name;".

Definition at line 2773 of file 3ddata.h.

Referenced by B2F_read_opts(), BUCK_read_opts(), TCAT_read_opts(), THD_array_3dim_from_block(), and ZCAT_read_opts().

#define INIT_DBARR name   
 

Value:

( (name) = XtNew(THD_datablock_array) ,\
     (name)->num = (name)->nall = 0 ,     \
     (name)->ar  = NULL )
Initialize a THD_datablock_array.

Definition at line 1165 of file 3ddata.h.

Referenced by THD_init_prefix_datablocks().

#define INIT_SARR name   
 

Value:

( (name) = XtNew(THD_string_array) , \
     (name)->num = (name)->nall = 0 ,   \
     (name)->ar  = NULL ,               \
     INIT_KILL((name)->kl) )
Initialize an empty dynamic string array named "name".

You must declare "THD_string_array *name;".

Definition at line 299 of file 3ddata.h.

Referenced by AFNI_read_inputs(), AFNI_rescan_timeseries_CB(), AFNI_write_many_dataset_CB(), ISQ_saver_CB(), NLFIT_get_many_MODELs(), PLUG_get_many_plugins(), T3D_read_images(), THD_extract_directories(), THD_extract_regular_files(), THD_get_all_executables(), THD_get_all_filenames(), THD_get_all_subdirs(), THD_get_many_timeseries(), THD_get_wildcard_filenames(), THD_getpathprogs(), THD_normalize_flist(), TT_read_opts(), and TT_whereami().

#define INIT_STAT_AUX ds,
nf,
ff   
 

Value:

do{ int is ;                                \
      for( is=0 ; is < MAX_STAT_AUX ; is++ )  \
         (ds)->stat_aux[is] = (is < (nf)) ? (ff)[is] : 0.0 ; } while(0)
Macro to initialize the global stat_aux data in a dataset.

Note that each sub-brick now has its own stat_aux data, and this global data is only used for the older (non-bucket) functional dataset types such as "fico".

Definition at line 2630 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), EDIT_empty_copy(), main(), T3D_save_file_CB(), THD_3dim_from_block(), and THD_warp3D().

#define INIT_XTARR name   
 

Value:

( (name) = XtNew(XtPointer_array) , \
     (name)->num = (name)->nall = 0 ,  \
     (name)->ar  = NULL ,              \
     (name)->ic  = NULL   )
Initialize dynamic XtPointer array named "name".

You must declare "XtPointer_array *name;".

Definition at line 225 of file 3ddata.h.

Referenced by AFNI_add_interruptable(), AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), B2F_read_opts(), BUCK_read_opts(), TCAT_read_opts(), THD_fetch_many_datasets(), and THD_init_alldir_datablocks().

#define INVALIDATE_BSTAT bst       ( (bst).min = 1.0 , (bst).max = -1.0 )
 

Make bst have invalid data.

Definition at line 1438 of file 3ddata.h.

Referenced by AFNI_copy_statistics(), THD_3dim_from_block(), THD_datablock_apply_atr(), THD_get_brick_stats(), THD_load_statistics(), THD_setup_mastery(), THD_update_one_bstat(), and THD_update_statistics().

#define ISANAT dset       ( ISVALID_DSET(dset) && ISANATTYPE((dset)->type) )
 

Determine if dset is an anatomical dataset.

Definition at line 2075 of file 3ddata.h.

Referenced by AFNI_force_adoption(), AFNI_write_many_dataset_CB(), DRAW_choose_CB(), DUMP_main(), EDIT_dset_items(), EDIT_one_dataset(), main(), NOTES_choose_CB(), NUD_choose_CB(), patch_PLUGIN_dataset_links(), PLUG_choose_dataset_CB(), PLUTO_add_dset(), PLUTO_dset_check(), RCREND_choose_CB(), REND_choose_CB(), RT_tell_afni_one(), SUMA_FormAfnidset(), SUMA_VolParFromDset(), T3D_read_images(), TAG_check_copyset(), TAG_check_dataset(), THD_array_3dim_from_block(), THD_dataset_info(), THD_init_session(), THD_open_tcat(), THD_order_session(), THD_setup_mastery(), and verify_inputs().

#define ISANATBUCKET dset       ( ISANAT(dset) && (dset)->func_type == ANAT_BUCK_TYPE )
 

Determine if dset is an anatomical bucket dataset

Definition at line 2087 of file 3ddata.h.

Referenced by AFNI_write_many_dataset_CB(), DRAW_choose_CB(), main(), NOTES_choose_CB(), NUD_choose_CB(), patch_PLUGIN_dataset_links(), PLUG_choose_dataset_CB(), RCREND_choose_CB(), REND_choose_CB(), and THD_setup_mastery().

#define ISANATTYPE nn       ( (nn) == HEAD_ANAT_TYPE || (nn) == GEN_ANAT_TYPE )
 

Determine if nn is an anatomical dataset type code.

Definition at line 2071 of file 3ddata.h.

Referenced by main(), and T3D_check_outliers().

#define ISBUCKET dset       ( ISANATBUCKET(dset) || ISFUNCBUCKET(dset) )
 

Determine if dset is a bucket dataset (functional or anatomical)

Definition at line 2095 of file 3ddata.h.

Referenced by AFNI_choose_dataset_CB(), EDIT_one_dataset(), and main().

#define ISFUNC dset       ( ISVALID_DSET(dset) && ISFUNCTYPE((dset)->type) )
 

Determine if dset is a functional dataset.

Definition at line 2067 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_do_many_writes(), AFNI_make_descendants_old(), AFNI_refashion_dataset(), AFNI_write_dataset_CB(), AFNI_write_many_dataset_CB(), DRAW_finalize_dset_CB(), DUMP_main(), EDIT_dset_items(), EDIT_main(), EDIT_one_dataset(), main(), PLUG_choose_dataset_CB(), PLUTO_dset_check(), populate_nifti_image(), RT_tell_afni_one(), T3D_anatomy_parent_CB(), T3D_save_file_CB(), THD_3dim_from_block(), THD_array_3dim_from_block(), THD_dataset_info(), THD_init_session(), THD_order_session(), and THD_setup_mastery().

#define ISFUNCBUCKET dset       ( ISFUNC(dset) && (dset)->func_type == FUNC_BUCK_TYPE )
 

Determine if dset is a functional bucket dataset

Definition at line 2091 of file 3ddata.h.

Referenced by AFNI_write_many_dataset_CB(), DRAW_choose_CB(), main(), NOTES_choose_CB(), NUD_choose_CB(), patch_PLUGIN_dataset_links(), PLUG_choose_dataset_CB(), RCREND_choose_CB(), RCREND_set_thr_pval(), REND_choose_CB(), REND_set_thr_pval(), and THD_setup_mastery().

#define ISFUNCTYPE nn       ( (nn) == HEAD_FUNC_TYPE || (nn) == GEN_FUNC_TYPE )
 

Determine if nn is a functional dataset type code.

Definition at line 2063 of file 3ddata.h.

Referenced by COPY_main(), main(), T3D_check_data(), T3D_read_images(), T3D_setup_stat_aux(), T3D_type_av_CB(), and THD_3dim_from_block().

#define ISHEAD dset       ( ISVALID_DSET(dset) && ISHEADTYPE((dset)->type) )
 

Determine if dset is a head dataset (vs. non-head).

Definition at line 2083 of file 3ddata.h.

Referenced by AFNI_fimmer_compute(), check_one_output_file(), check_output_file(), fim3d_fimmer_compute(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), PERMTEST_main(), RT_fim_recurse(), THRESH_main(), write_afni_data(), write_afni_fict(), and write_afni_fizt().

#define ISHEADTYPE nn       ( (nn) == HEAD_ANAT_TYPE || (nn) == HEAD_FUNC_TYPE )
 

Determine if nn is a head dataset type code.

Definition at line 2079 of file 3ddata.h.

#define ISVALID_3DIM_DATASET ds   
 

Value:

( (ds) != NULL && (ds)->type >= FIRST_3DIM_TYPE && \
                     (ds)->type <= LAST_3DIM_TYPE  && \
      ISVALID_DATABLOCK((ds)->dblk)                  )
Determine if ds is a pointer to a valid dataset.

Definition at line 2052 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_andersonville(), AFNI_autorange_label(), AFNI_bucket_label_CB(), AFNI_choose_dataset_CB(), AFNI_copy_statistics(), AFNI_crosshair_label(), AFNI_dataset_slice(), AFNI_finalize_dataset_CB(), AFNI_follower_dataset(), AFNI_force_adoption(), AFNI_initialize_view(), AFNI_make_descendants_old(), AFNI_mark_for_death(), AFNI_marks_transform_CB(), AFNI_range_label(), AFNI_rescan_session_OLD(), AFNI_see_func_CB(), AFNI_set_thr_pval(), AFNI_set_viewpoint(), AFNI_set_window_titles(), AFNI_setup_viewing(), AFNI_thr_scale_drag_CB(), AFNI_write_dataset_CB(), check_one_output_file(), copy_dset(), create_bucket(), DUP_main(), duplicate_dataset(), EDIT_add_bricklist(), EDIT_dset_items(), EDIT_empty_copy(), EDIT_full_copy(), EDIT_substitute_brick(), EDIT_wod_copy(), get_dimensions(), get_inputs(), get_options(), main(), make_PLUGIN_dataset_link(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), NUD_brick_av_label_CB(), patch_PLUGIN_dataset_links(), PC_read_opts(), PLUG_choose_dataset_CB(), PLUGIN_dset_check(), PLUTO_4D_to_nothing(), PLUTO_add_dset(), r_new_resam_dset(), RCREND_choose_av_label_CB(), read_input_data(), RENAME_main(), REND_choose_av_label_CB(), RIC_CalcCoeffAB(), RIC_CalcVoxelMeans(), RIC_CorrectDataset(), RT_finish_dataset(), s2v_nodes2volume(), terminate(), THD_3dim_dataset_to_brick(), THD_append_dataset_keywords(), THD_dataset_info(), THD_delete_3dim_dataset(), THD_load_statistics(), THD_set_dataset_attributes(), THD_setup_bricks(), THD_store_dataset_keywords(), THD_update_one_bstat(), THD_update_statistics(), THD_write_3dim_dataset(), UC_read_opts(), valid_resam_inputs(), write_afni_data(), write_afni_fict(), and write_afni_fizt().

#define ISVALID_BSTAT bst       ( (bst).min <= (bst).max )
 

Check if bst is a valid sub-brick statistic.

Definition at line 1434 of file 3ddata.h.

Referenced by AFNI_range_setter(), AFNI_view_xyz_CB(), THD_setup_mastery(), THD_update_one_bstat(), and THD_update_statistics().

#define ISVALID_DATABLOCK bk       ( (bk) != NULL && (bk)->type == DATABLOCK_TYPE )
 

Check if datablock is OK.

Definition at line 1145 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_alloc_datablock(), THD_anonymize_dset(), THD_append_datablock_keywords(), THD_copy_datablock_auxdata(), THD_count_databricks(), THD_delete_datablock(), THD_erase_all_atr(), THD_erase_one_atr(), THD_find_atr(), THD_force_malloc_type(), THD_init_datablock_brick(), THD_init_datablock_keywords(), THD_init_datablock_labels(), THD_init_datablock_stataux(), THD_insert_atr(), THD_load_1D(), THD_load_3D(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_datablock(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), THD_need_brick_factor(), THD_purge_datablock(), THD_purge_one_brick(), THD_read_all_atr(), THD_set_atr(), THD_set_dataset_attributes(), THD_store_datablock_keywords(), THD_store_datablock_label(), THD_store_datablock_stataux(), THD_write_3dim_dataset(), THD_write_atr(), THD_write_datablock(), and THD_zerofill_dataset().

#define ISVALID_DATAXES dax       ( (dax) != NULL && (dax)->type == DATAXES_TYPE )
 

Check if dax is a valid THD_dataxes struct.

Definition at line 1326 of file 3ddata.h.

Referenced by r_dxyz_mod_dataxes(), sync_master_opts(), THD_edit_dataxes(), THD_oriented_brick(), THD_setup_bricks(), and valid_resam_inputs().

#define ISVALID_DBLK   ISVALID_DATABLOCK
 

Synonym for ISVALID_DATABLOCK.

Definition at line 1149 of file 3ddata.h.

Referenced by THD_load_tcat().

#define ISVALID_DISKPTR dk       ( (dk)!=NULL && (dk)->type==DISKPTR_TYPE )
 

Determine if THD_diskptr dk is valid.

Definition at line 957 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_delete_diskptr(), THD_init_diskptr_names(), THD_load_datablock(), THD_set_dataset_attributes(), THD_write_3dim_dataset(), THD_write_atr(), and THD_write_datablock().

#define ISVALID_DSET   ISVALID_3DIM_DATASET
 

Determine if ds is a pointer to a valid dataset.

Definition at line 2059 of file 3ddata.h.

Referenced by AFNI_bucket_label_CB(), AFNI_dataset_to_obj(), AFNI_dicomm_to_xyz(), AFNI_finalize_read_Web_CB(), AFNI_force_adoption(), AFNI_ijk_to_xyz(), AFNI_process_plugout(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), AFNI_time_index_CB(), AFNI_underlay_CB(), AFNI_xyz_to_dicomm(), AFNI_xyz_to_ijk(), BFIT_prepare_dataset(), CREN_dset_axes(), disp_opts_data(), disp_param_t(), disp_range_3dmm(), disp_v2s_param_t(), do_xrestore_stuff(), DRAW_choose_CB(), DRAW_copy_dset(), DSET2_dset_recv(), DSET2_func(), DSET_in_global_session(), DSETN_func(), DSETN_main(), EDIT_wod_copy(), ENTROPY_dataset(), init_options(), load_histo(), main(), MCW_hash_idcode(), NOTES_choose_CB(), NUD_choose_CB(), PLUTO_dset_redisplay_mode(), RCREND_autorange_label(), RCREND_choose_CB(), RCREND_load_dsl(), RCREND_range_label(), RCREND_reload_dataset(), RCREND_reload_func_dset(), RCREND_set_thr_pval(), RCREND_state_to_widgets(), RCREND_xhair_underlay(), rd_disp_dset_info(), REND_autorange_label(), REND_choose_CB(), REND_load_dsl(), REND_range_label(), REND_set_thr_pval(), REND_state_to_widgets(), RT_tell_afni(), RT_tell_afni_one(), s2v_nodes2volume(), set_global_dsets_from_ids(), SUMA_Get_isosurface_datasets(), SUMA_make_vnlist(), SUMA_THD_handedness(), sync_master_opts(), TAG_get_copy_CB(), TAG_get_dset_CB(), THD_add_bricks(), THD_anonymize_dset(), THD_autonudge(), THD_average_one_timeseries(), THD_average_timeseries(), THD_axcode(), THD_check_idcodes(), THD_datablock_apply_atr(), THD_dataset_center(), THD_dataset_mismatch(), THD_dataset_rowfillin(), THD_dataset_tshift(), THD_dataset_zfillin(), THD_extract_array(), THD_extract_series(), THD_fetch_many_datasets(), THD_get_dset_rowcount(), THD_handedness(), THD_init_session(), THD_insert_series(), THD_load_datablock(), THD_load_tcat(), THD_makemask(), thd_mask_from_brick(), THD_mean_brick(), THD_median_brick(), THD_need_brick_factor(), THD_newprefix(), THD_nimlize_dsetatr(), THD_oriented_brick(), THD_outlier_count(), THD_read_dvecmat(), THD_rms_brick(), THD_set_storage_mode(), THD_setup_mastery(), THD_subbrick_to_niml(), THD_timeof_slice(), THD_timeof_vox(), THD_warp3D(), THD_write_1D(), THD_write_minc(), THD_write_nifti(), THD_write_nimlatr(), THD_zerofill_dataset(), THD_zeropad(), tross_Add_Note(), tross_Addto_History(), tross_Append_History(), tross_Copy_History(), tross_Delete_Note(), tross_Get_History(), tross_Get_Note(), tross_Get_Notecount(), tross_Get_Notedate(), tross_Make_History(), tross_Replace_History(), tross_Store_Note(), and validate_datasets().

#define ISVALID_MEM_CODE mm   
 

Value:

( (mm) == DATABLOCK_MEM_MALLOC || (mm) == DATABLOCK_MEM_MMAP \
                                 || (mm) == DATABLOCK_MEM_ANY  \
                                 || (mm) == DATABLOCK_MEM_SHARED )
Determine if mm is a valid memory allocation code.

Definition at line 1010 of file 3ddata.h.

Referenced by EDIT_dset_items().

#define ISVALID_SESSION ss       ( (ss) != NULL && (ss)->type == SESSION_TYPE )
 

Determine if ss points to a valid THD_session.

Definition at line 2862 of file 3ddata.h.

Referenced by AFNI_andersonville(), AFNI_append_sessions(), AFNI_fimmer_compute(), AFNI_fimmer_execute(), AFNI_force_adoption(), AFNI_make_descendants_old(), AFNI_mark_for_death(), AFNI_marks_transform_CB(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), and THD_dset_in_session().

#define ISVALID_SESSIONLIST sl       ( (sl)!=NULL && (sl)->type==SESSIONLIST_TYPE )
 

Determine if sl is a valid THD_sessionlist

Definition at line 2897 of file 3ddata.h.

Referenced by AFNI_andersonville(), AFNI_make_descendants_old(), AFNI_mark_for_death(), AFNI_purge_dsets(), THD_check_idcodes(), THD_dset_in_sessionlist(), and THD_reconcile_parents().

#define ISVALID_STATISTIC st       ( (st) != NULL && (st)->type == STATISTICS_TYPE )
 

Check if st is a valid THD_statistics struct.

Definition at line 1430 of file 3ddata.h.

Referenced by AFNI_autorange_label(), AFNI_copy_statistics(), AFNI_range_label(), AFNI_range_setter(), AFNI_view_xyz_CB(), main(), NUD_update_base(), RCREND_autorange_label(), RCREND_range_label(), REND_autorange_label(), REND_range_label(), THD_dataset_info(), THD_load_statistics(), THD_set_dataset_attributes(), and THD_setup_mastery().

#define ISVALID_TIMEAXIS tax       ((tax) != NULL && (tax)->type == TIMEAXIS_TYPE)
 

Check if tax points to a valid THD_timeaxis struct.

Definition at line 1403 of file 3ddata.h.

Referenced by EDIT_dset_items(), EDIT_empty_copy(), RIC_CalcCoeffAB(), RIC_CorrectDataset(), THD_delete_3dim_dataset(), THD_timeof(), THD_timeof_slice(), and THD_timeof_vox().

#define ISVALID_WARP ww   
 

Value:

( (ww) != NULL &&                  \
                           (ww)->type >= FIRST_WARP_TYPE && \
                           (ww)->type <= LAST_WARP_TYPE )
Check if ww is a good warp.

Definition at line 834 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_dataset_slice(), AFNI_follower_dataset(), and EDIT_dset_items().

#define ISZERO_IDCODE id       ((id).str[0] == '\0')
 

Check if the ID code is zero.

Definition at line 1494 of file 3ddata.h.

Referenced by AFNI_rescan_session_OLD(), DSET2_dset_recv(), main(), PLUG_choose_dataset_CB(), PLUTO_find_dset(), RCREND_save_state(), RCREND_state_to_widgets(), REND_save_state(), REND_state_to_widgets(), set_global_dsets_from_ids(), THD_3dim_from_block(), THD_datablock_apply_atr(), THD_dataset_info(), THD_dset_in_session(), THD_reconcile_parents(), and THD_set_dataset_attributes().

#define KILL_STATISTIC st   
 

Value:

do{ if( ISVALID_STATISTIC(st) ){  \
        XtFree((char *)(st)->bstat) ; XtFree((char *)(st)) ; } } while(0)
Destroy a THD_statistics struct.

Definition at line 1442 of file 3ddata.h.

Referenced by main().

#define LAST_3DIM_TYPE   3
 

Definition at line 1535 of file 3ddata.h.

Referenced by EDIT_dset_items(), main(), T3D_create_widgets(), and THD_3dim_from_block().

#define LAST_ANAT_TYPE   11
 

Definition at line 1901 of file 3ddata.h.

Referenced by EDIT_dset_items(), main(), Syntax(), T3D_create_widgets(), and T3D_initialize_user_data().

#define LAST_ATR_TYPE   2
 

Definition at line 431 of file 3ddata.h.

Referenced by THD_read_all_atr().

#define LAST_FUNC_TYPE   11
 

Definition at line 1710 of file 3ddata.h.

Referenced by COPY_main(), EDIT_dset_items(), main(), Syntax(), T3D_create_widgets(), T3D_initialize_user_data(), and ZPAD_main().

#define LAST_MAPPING_TYPE   0
 

Definition at line 486 of file 3ddata.h.

#define LAST_ORIENT_TYPE   5
 

Definition at line 1224 of file 3ddata.h.

Referenced by EDIT_dset_items(), mri_brainormalize(), T3D_create_widgets(), and T3D_read_images().

#define LAST_RESAM_TYPE   3
 

Definition at line 763 of file 3ddata.h.

Referenced by AFNI_load_defaults(), AFNI_write_dataset_CB(), display_help_menu(), get_options(), init_options(), resam_str2mode(), and valid_resam_inputs().

#define LAST_STAT_TYPE   10
 

Definition at line 1713 of file 3ddata.h.

#define LAST_STORAGE_MODE   11
 

Definition at line 925 of file 3ddata.h.

Referenced by THD_set_storage_mode().

#define LAST_VIEW_TYPE   2
 

Definition at line 1562 of file 3ddata.h.

Referenced by AFNI_andersonville(), AFNI_append_sessions(), AFNI_choose_dataset_CB(), AFNI_drive_purge_memory(), AFNI_finalize_dataset_CB(), AFNI_finalize_read_sess_CB(), AFNI_finalize_read_Web_CB(), AFNI_force_adoption(), AFNI_initialize_view(), AFNI_make_descendants_old(), AFNI_mark_for_death(), AFNI_marks_transform_CB(), AFNI_purge_dsets(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), AFNI_setup_viewing(), AFNI_switchview_CB(), BUCK_read_opts(), EDIT_dset_items(), main(), PLUTO_popup_dset_chooser(), RENAME_main(), T3D_create_widgets(), T3D_initialize_user_data(), TCAT_read_opts(), THD_check_idcodes(), THD_dataset_headname(), THD_dset_in_session(), THD_init_diskptr_names(), THD_is_dataset(), THD_order_session(), THD_reconcile_parents(), and THD_rename_dataset_files().

#define LAST_WARP_TYPE   1
 

Definition at line 742 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define LOAD_INVERSE_LMAP map   
 

Value:

( (map).mbac = MAT_INV((map).mfor) ,          \
     (map).svec = MATVEC((map).mbac,(map).bvec) ,\
     NEGATE_FVEC3((map).svec) )
Use the matrix operations to define a macro to load the inverse to a THD_linear_mapping once the forward is done.

Definition at line 513 of file 3ddata.h.

Referenced by AFNI_make_affwarp_12(), and main().

#define LONGEST_3DIM_TYPESTR   strlen(HEAD_ANAT_STR)
 

Definition at line 1537 of file 3ddata.h.

Referenced by T3D_create_widgets().

#define LONGEST_ANAT_TYPESTR   strlen(ANAT_MRA_STR)
 

Definition at line 1911 of file 3ddata.h.

Referenced by T3D_create_widgets().

#define LONGEST_FUNC_TYPESTR   strlen(FUNC_PT_STR)
 

Definition at line 1721 of file 3ddata.h.

Referenced by T3D_create_widgets().

#define LONGEST_ORIENT_TYPESTR   strlen(ORI_P2A_STR)
 

Definition at line 1226 of file 3ddata.h.

Referenced by T3D_create_widgets().

#define LONGEST_VIEW_TYPESTR   strlen(VIEW_REGISTERED_STR)
 

Definition at line 1564 of file 3ddata.h.

Referenced by T3D_create_widgets().

#define MAPPING_LINEAR_FEND   (XtOffsetOf(THD_linear_mapping,top)+sizeof(THD_fvec3))
 

Definition at line 519 of file 3ddata.h.

#define MAPPING_LINEAR_FSIZE   ((MAPPING_LINEAR_FEND-MAPPING_LINEAR_FSTART)/sizeof(float))
 

Definition at line 520 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define MAPPING_LINEAR_FSTART   XtOffsetOf(THD_linear_mapping,mfor)
 

Definition at line 518 of file 3ddata.h.

Referenced by THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define MAPPING_LINEAR_STR   "LINEAR_MAPPING"
 

Definition at line 483 of file 3ddata.h.

#define MAPPING_LINEAR_TYPE   0
 

Definition at line 482 of file 3ddata.h.

Referenced by AFNI_concatenate_lmap(), AFNI_make_affwarp_12(), AFNI_make_voxmap(), AFNI_make_warp(), main(), THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKACTION_NONE   0
 

Definition at line 594 of file 3ddata.h.

Referenced by AFNI_marks_action_CB(), and AFNI_marks_edits_CB().

#define MARKACTION_REGISTER   2
 

Definition at line 596 of file 3ddata.h.

#define MARKACTION_WARP   1
 

Definition at line 595 of file 3ddata.h.

Referenced by AFNI_marks_transform_CB().

#define MARKS_ASIZE   MARKS_MAXFLAG
 

Definition at line 586 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_ASTART   XtOffsetOf(THD_marker_set,aflags)
 

Definition at line 587 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_FSIZE   (MARKS_MAXNUM*3)
 

Definition at line 577 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_FSTART   XtOffsetOf(THD_marker_set,xyz)
 

Definition at line 578 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_HSIZE   (MARKS_MAXNUM*MARKS_MAXHELP)
 

Definition at line 583 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_HSTART   XtOffsetOf(THD_marker_set,help)
 

Definition at line 584 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_LSIZE   (MARKS_MAXNUM*MARKS_MAXLAB)
 

Definition at line 580 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_LSTART   XtOffsetOf(THD_marker_set,label)
 

Definition at line 581 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_MAXFLAG   8
 

Definition at line 553 of file 3ddata.h.

Referenced by AFNI_init_warp(), main(), T3D_save_file_CB(), THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MARKS_MAXHELP   256
 

Definition at line 552 of file 3ddata.h.

Referenced by AFNI_init_warp(), AFNI_initialize_view(), main(), and T3D_save_file_CB().

#define MARKS_MAXLAB   20
 

Definition at line 551 of file 3ddata.h.

Referenced by AFNI_init_warp(), main(), and T3D_save_file_CB().

#define MARKS_MAXNUM   10
 

Definition at line 550 of file 3ddata.h.

Referenced by AFNI_init_warp(), AFNI_initialize_view(), AFNI_marks_action_CB(), AFNI_marks_edits_CB(), AFNI_marktog_CB(), AFNI_overlay(), main(), T3D_save_file_CB(), THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define MARKSET_ALIGN   1
 

Definition at line 591 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define MARKSET_BOUNDING   2
 

Definition at line 592 of file 3ddata.h.

Referenced by AFNI_make_warp(), and AFNI_marks_quality_check().

#define MASTER_HELP_STRING
 

Help string to explain dataset "mastering" at length.

Definition at line 3187 of file 3ddata.h.

Referenced by AFNI_syntax(), and CALC_Syntax().

#define MASTER_SHORTHELP_STRING
 

Value:

"INPUT DATASET NAMES\n"                                                        \
 "-------------------\n"                                                        \
 "This program accepts datasets that are modified on input according to the\n"  \
 "following schemes:\n"                                                         \
 "  'r1+orig[3..5]'                                    {sub-brick selector}\n"  \
 "  'r1+orig<100.200>'                                 {sub-range selector}\n"  \
 "  'r1+orig[3..5]<100..200>'                          {both selectors}\n"      \
 "  '3dcalc( -a r1+orig -b r2+orig -expr 0.5*(a+b) )'  {calculation}\n"         \
 "For the gruesome details, see the output of 'afni -help'.\n"
Help string to explain dataset "mastering" briefly.

Definition at line 3174 of file 3ddata.h.

Referenced by display_help_menu(), DT_Syntax(), EX_Syntax(), FDR_Syntax(), help_message(), main(), MRG_Syntax(), PC_syntax(), SC_Syntax(), Syntax(), TRIC_printhelp(), TS_syntax(), TT_syntax(), UC_syntax(), and ZCAT_Syntax().

#define MAX_ALLOWED_DEVIATION   2.0
 

Definition at line 695 of file 3ddata.h.

Referenced by AFNI_marks_quality_check().

#define MAX_DSET_NOTES   999
 

Definition at line 3799 of file 3ddata.h.

Referenced by main(), NOTES_add_CB(), tross_Add_Note(), tross_Delete_Note(), tross_Get_Note(), tross_Get_Notedate(), and tross_Store_Note().

#define MAX_NOTE_SIZE   4000
 

Definition at line 3800 of file 3ddata.h.

#define MAX_STAT_AUX   64
 

Definition at line 1793 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_fimmer_compute(), AFNI_follower_dataset(), AFNI_init_warp(), EDIT_dset_items(), EDIT_empty_copy(), EDIT_main(), fim3d_fimmer_compute(), main(), RT_fim_recurse(), T3D_data_to_widgets(), T3D_initialize_user_data(), T3D_widgets_to_data(), THD_set_dataset_attributes(), THD_warp3D(), write_afni_data(), write_afni_fict(), and write_afni_fizt().

#define MCW_IDDATE   48
 

Size of ID date string.

Definition at line 1459 of file 3ddata.h.

Referenced by THD_3dim_from_block(), and THD_datablock_apply_atr().

#define MCW_IDPREFIX   "NIH_"
 

Definition at line 1450 of file 3ddata.h.

#define MCW_IDSIZE   32
 

Size of ID code string. 27 Sep 2001: increased from 16 to 32.

Definition at line 1456 of file 3ddata.h.

Referenced by AFNI_drive_purge_memory(), AFNI_drive_switch_anatomy(), AFNI_drive_switch_function(), MCW_hash_idcode(), PLUTO_dset_finder(), PLUTO_find_dset_idc(), RCREND_read_states(), REND_read_states(), THD_3dim_from_block(), THD_datablock_apply_atr(), THD_niml_to_dataset(), THD_open_3D(), and THD_open_nifti().

#define MCW_strncpy dest,
src,
n       ( (void) strncpy( (dest) , (src) , (n)-1 ) , (dest)[(n)-1] = '\0' )
 

Safe version of strncpy, which always leaves a NUL at the end.

The standard stupid strncpy(dest,src,n) might not leave a NUL character at the end if the src string is too long. This criminal behavior is reformed by this macro.

Definition at line 199 of file 3ddata.h.

Referenced by add_option_to_PLUGIN_interface(), add_string_to_PLUGIN_interface(), adwarp_follower_dataset(), AFNI_choose_dataset_CB(), AFNI_crosshair_pop_CB(), AFNI_drive_open_graph_1D(), AFNI_drive_open_graph_xy(), AFNI_drive_purge_memory(), AFNI_drive_switch_anatomy(), AFNI_drive_switch_function(), AFNI_drive_switch_session(), AFNI_fimmer_compute(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_initialize_view(), AFNI_marks_transform_CB(), AFNI_parse_args(), AFNI_process_plugout(), AFNI_read_images(), AFNI_read_inputs(), B2F_read_opts(), BUCK_read_opts(), CALC_read_opts(), CORD_main(), DRAW_copy_dset(), DT_read_opts(), duplicate_dataset(), EDIT_dset_items(), EDIT_empty_copy(), ENV_add_numeric(), ENV_add_string(), ENV_coorder(), EX_read_opts(), get_options(), main(), make_PLUGIN_dataset_link(), MCW_choose_timeseries(), MCW_hash_idcode(), MRG_read_opts(), new_PLUGIN_interface_1999(), new_RT_input(), NLFIT_read_MODEL(), PC_read_opts(), PLUG_read_plugin(), PLUGIN_init(), PLUTO_dset_finder(), PLUTO_find_dset_idc(), PLUTO_set_butcolor(), PLUTO_set_runlabels(), PLUTO_set_sequence(), process_NIML_SUMA_ixyz(), RCREND_accum_lab_CB(), RCREND_read_states(), read_input_data(), read_options(), REND_read_states(), RT_fim_recurse(), RT_process_info(), SC_read_opts(), T3D_anatomy_parent_CB(), T3D_geometry_parent_CB(), T3D_initialize_user_data(), T3D_save_file_CB(), T3D_widgets_to_data(), TCAT_read_opts(), THD_3dim_from_block(), THD_datablock_apply_atr(), THD_datablock_from_atr(), THD_init_diskptr_names(), THD_init_session(), THD_open_1D(), THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), TT_read_opts(), UC_read_opts(), and ZCAT_read_opts().

#define MIN_ALLOWED_DEVIATION   0.5
 

Definition at line 696 of file 3ddata.h.

Referenced by AFNI_marks_quality_check().

#define MINC_FLOATIZE_MASK   1
 

Definition at line 3340 of file 3ddata.h.

Referenced by main(), and THD_write_minc().

#define MISMATCH_CENTER   (1<<0)
 

Definition at line 3383 of file 3ddata.h.

Referenced by THD_dataset_mismatch().

#define MISMATCH_DELTA   (1<<1)
 

Definition at line 3384 of file 3ddata.h.

Referenced by main(), THD_dataset_mismatch(), and VL_command_line().

#define MISMATCH_DIMEN   (1<<3)
 

Definition at line 3386 of file 3ddata.h.

Referenced by THD_dataset_mismatch(), and VL_command_line().

#define MISMATCH_ORIENT   (1<<2)
 

Definition at line 3385 of file 3ddata.h.

Referenced by main(), THD_dataset_mismatch(), and VL_command_line().

#define MMAP_THRESHOLD   999999
 

A brick file should have this many bytes before we try to use mmap

Definition at line 1017 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), AFNI_syntax(), THD_datablock_from_atr(), and THD_force_malloc_type().

#define NEEDS_DSET_INDEX   2
 

MCW_function_list possible bitmask flag

Definition at line 148 of file 3ddata.h.

Referenced by plot_graphs(), and PLUGIN_init().

#define NMARK_ALIGN   5
 

Number of orig->acpc markers.

Definition at line 602 of file 3ddata.h.

Referenced by main(), and T3D_save_file_CB().

#define NMARK_BOUNDING   6
 

Number of acpc->tlrc markers.

Definition at line 657 of file 3ddata.h.

Referenced by AFNI_init_warp().

#define NSTR_SHORT_RESAM   2
 

Definition at line 769 of file 3ddata.h.

#define NUM_DSET_TYPES   (LAST_FUNC_TYPE + LAST_ANAT_TYPE + 2)
 

Definition at line 1909 of file 3ddata.h.

Referenced by COPY_main(), PLUGIN_init(), and ZPAD_main().

#define OKHOST hh       TRUST_host(hh) ;
 

Definition at line 3313 of file 3ddata.h.

#define ORI_A2P_STR   "Anterior-to-Posterior"
 

Definition at line 1212 of file 3ddata.h.

#define ORI_A2P_TYPE   3
 

Definition at line 1211 of file 3ddata.h.

Referenced by AFNI_init_warp(), brainnormalize_coord(), CREN_dset_axes(), DBLE_mat_to_dicomm(), EDIT_dset_items(), EDIT_empty_copy(), main(), mri_brainormalize(), new_RT_input(), RT_registration_3D_onevol(), RT_start_dataset(), SNGL_mat_to_dicomm(), SUMA_BrainVoyager_Read_vmr(), SUMA_flip_orient(), SUMA_orcode_to_orstring(), SUMA_orstring_to_orcode(), SUMA_THD_3dmm_to_dicomm(), SUMA_THD_dicomm_to_3dmm(), SUMA_VolDims(), T3D_save_file_CB(), THD_3dim_from_block(), THD_3dmm_to_dicomm(), THD_axcode(), THD_coorder_fill(), THD_dataset_info(), THD_dicomm_to_3dmm(), THD_matrix_to_orientation(), THD_open_3D(), THD_open_ctfmri(), THD_open_minc(), THD_open_mpeg(), THD_oriented_brick(), THD_setup_bricks(), THD_warp3D(), THD_zeropad(), and VOLREG_main().

#define ORI_GEN_STR   "General"
 

Definition at line 1221 of file 3ddata.h.

#define ORI_GEN_TYPE   6
 

Definition at line 1220 of file 3ddata.h.

#define ORI_I2S_STR   "Inferior-to-Superior"
 

Definition at line 1215 of file 3ddata.h.

#define ORI_I2S_TYPE   4
 

Definition at line 1214 of file 3ddata.h.

Referenced by AFNI_init_warp(), brainnormalize_coord(), CREN_dset_axes(), DBLE_mat_to_dicomm(), EDIT_dset_items(), EDIT_empty_copy(), main(), mri_brainormalize(), RT_registration_3D_onevol(), RT_start_dataset(), SNGL_mat_to_dicomm(), SUMA_flip_orient(), SUMA_orcode_to_orstring(), SUMA_orstring_to_orcode(), SUMA_THD_3dmm_to_dicomm(), SUMA_THD_dicomm_to_3dmm(), SUMA_VolDims(), T3D_save_file_CB(), THD_3dim_from_block(), THD_3dmm_to_dicomm(), THD_axcode(), THD_coorder_fill(), THD_dataset_info(), THD_dicomm_to_3dmm(), THD_matrix_to_orientation(), THD_open_3D(), THD_open_analyze(), THD_open_ctfsam(), THD_open_minc(), THD_open_mpeg(), THD_oriented_brick(), THD_setup_bricks(), THD_warp3D(), THD_zeropad(), and VOLREG_main().

#define ORI_L2R_STR   "Left-to-Right"
 

Definition at line 1206 of file 3ddata.h.

#define ORI_L2R_TYPE   1
 

Definition at line 1205 of file 3ddata.h.

Referenced by brainnormalize_coord(), CREN_dset_axes(), DBLE_mat_to_dicomm(), EDIT_dset_items(), main(), mri_brainormalize(), new_RT_input(), RT_registration_3D_onevol(), RT_start_dataset(), SNGL_mat_to_dicomm(), SUMA_flip_orient(), SUMA_orcode_to_orstring(), SUMA_orstring_to_orcode(), SUMA_THD_3dmm_to_dicomm(), SUMA_THD_dicomm_to_3dmm(), SUMA_VolDims(), T3D_save_file_CB(), THD_3dim_from_block(), THD_3dmm_to_dicomm(), THD_dicomm_to_3dmm(), THD_matrix_to_orientation(), THD_open_analyze(), THD_open_ctfmri(), THD_open_minc(), THD_open_mpeg(), THD_oriented_brick(), THD_setup_bricks(), THD_zeropad(), and VOLREG_main().

#define ORI_P2A_STR   "Posterior-to-Anterior"
 

Definition at line 1209 of file 3ddata.h.

#define ORI_P2A_TYPE   2
 

Definition at line 1208 of file 3ddata.h.

Referenced by brainnormalize_coord(), CREN_dset_axes(), DBLE_mat_to_dicomm(), EDIT_dset_items(), main(), mri_brainormalize(), RT_registration_3D_onevol(), RT_start_dataset(), SNGL_mat_to_dicomm(), SUMA_flip_orient(), SUMA_orcode_to_orstring(), SUMA_orstring_to_orcode(), SUMA_THD_3dmm_to_dicomm(), SUMA_THD_dicomm_to_3dmm(), SUMA_VolDims(), T3D_save_file_CB(), THD_3dim_from_block(), THD_3dmm_to_dicomm(), THD_dicomm_to_3dmm(), THD_matrix_to_orientation(), THD_open_analyze(), THD_open_ctfsam(), THD_open_minc(), THD_oriented_brick(), THD_setup_bricks(), THD_zeropad(), and VOLREG_main().

#define ORI_R2L_STR   "Right-to-Left"
 

Definition at line 1203 of file 3ddata.h.

#define ORI_R2L_TYPE   0
 

Definition at line 1202 of file 3ddata.h.

Referenced by AFNI_init_warp(), brainnormalize_coord(), CREN_dset_axes(), DBLE_mat_to_dicomm(), EDIT_dset_items(), EDIT_empty_copy(), main(), mri_brainormalize(), RT_registration_3D_onevol(), RT_start_dataset(), SNGL_mat_to_dicomm(), SUMA_BrainVoyager_Read_vmr(), SUMA_flip_orient(), SUMA_orcode_to_orstring(), SUMA_orstring_to_orcode(), SUMA_THD_3dmm_to_dicomm(), SUMA_THD_dicomm_to_3dmm(), SUMA_VolDims(), T3D_save_file_CB(), THD_3dim_from_block(), THD_3dmm_to_dicomm(), THD_axcode(), THD_coorder_fill(), THD_dataset_info(), THD_dicomm_to_3dmm(), THD_matrix_to_orientation(), THD_open_3D(), THD_open_ctfsam(), THD_open_minc(), THD_oriented_brick(), THD_setup_bricks(), THD_warp3D(), THD_zeropad(), and VOLREG_main().

#define ORI_S2I_STR   "Superior-to-Inferior"
 

Definition at line 1218 of file 3ddata.h.

#define ORI_S2I_TYPE   5
 

Definition at line 1217 of file 3ddata.h.

Referenced by brainnormalize_coord(), CREN_dset_axes(), DBLE_mat_to_dicomm(), EDIT_dset_items(), main(), mri_brainormalize(), new_RT_input(), RT_registration_3D_onevol(), RT_start_dataset(), SNGL_mat_to_dicomm(), SUMA_BrainVoyager_Read_vmr(), SUMA_flip_orient(), SUMA_orcode_to_orstring(), SUMA_orstring_to_orcode(), SUMA_THD_3dmm_to_dicomm(), SUMA_THD_dicomm_to_3dmm(), SUMA_VolDims(), T3D_save_file_CB(), THD_3dim_from_block(), THD_3dmm_to_dicomm(), THD_dicomm_to_3dmm(), THD_matrix_to_orientation(), THD_open_ctfmri(), THD_open_minc(), THD_oriented_brick(), THD_setup_bricks(), THD_zeropad(), and VOLREG_main().

#define ORIENT_OPPOSITE orc       ( ((orc) % 2 == 0) ? ((orc)+1) : ((orc)-1) )
 

Definition at line 1252 of file 3ddata.h.

Referenced by main(), RT_start_dataset(), T3D_initialize_user_data(), THD_get_axis_direction(), and THD_init_session().

#define PATH_CONCAT pout,
p1,
p2   
 

Value:

do{ int zq ; strcpy((pout),(p1)) ; zq = strlen((pout)) ; \
      if( (pout)[zq-1] != '/' ) strcat((pout),"/") ;       \
      strcat((pout),(p2)) ; } while(0)
Concatenate strings p1 and p2 into string pout, making them a filesystem path.

If p1 doesn't end in a '/', the '/' between p1/p2 will be added. The pout array must be previously allocated.

Definition at line 346 of file 3ddata.h.

Referenced by T3D_anatomy_parent_CB(), T3D_check_data(), and T3D_geometry_parent_CB().

#define PREFIX_VIEW_TO_FILECODE pr,
vv,
fc       sprintf( (fc),"%s+%s",(pr),(vv) )
 

Convert a file prefix and viewcode into a filecode (prefix+view).

Definition at line 961 of file 3ddata.h.

Referenced by THD_init_diskptr_names().

#define PROCESS_MRI_IMAGE   4
 

MCW_function_list possible bitmask flag

Definition at line 151 of file 3ddata.h.

Referenced by plot_graphs(), and PLUGIN_init().

#define PURGE_DSET ds   
 

Value:

do{ if( ISVALID_3DIM_DATASET(ds) && DSET_ONDISK(ds) )                 \
         (void) THD_purge_datablock( (ds)->dblk , DATABLOCK_MEM_ANY ) ; \
  } while(0)
Purge the data of dataset ds from memory (you can reload it later)

Definition at line 2226 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_drive_purge_memory(), AFNI_purge_dsets(), AFNI_refashion_dataset(), DSET_cor(), main(), process(), SUMA_Get_isosurface_datasets(), and TT_purge_atlas().

#define RELOAD_STATS dset   
 

Value:

if( ISVALID_3DIM_DATASET((dset)) &&                                       \
      ( !ISVALID_STATISTIC((dset)->stats) ||                                \
        ( (dset)->dblk->nvals > 1 &&                                        \
          (dset)->stats->bstat[1].min > (dset)->stats->bstat[1].max ) ) ){  \
     THD_load_statistics((dset)) ; }
Macro to load brick statistics of a dataset if it
  • doesn't have statistics already, or
  • has bad statistics from the (very) old to3d bug

Definition at line 2591 of file 3ddata.h.

Referenced by AFNI_autorange_label(), AFNI_range_label(), RCREND_autorange_label(), REND_autorange_label(), and THD_load_statistics().

#define REMOVEFROM_SARR name,
ijk   
 

Value:

do{ SINGLE_KILL((name)->kl,(name)->ar[(ijk)]) ; \
     (name)->ar[(ijk)] = NULL ; } while(0)
Remove the ijk-th string from dynamic string array "name".

Definition at line 322 of file 3ddata.h.

Referenced by THD_init_prefix_datablocks(), and THD_normalize_flist().

#define RESAM_BLOCK_STR   "Blocky Interpolation"
 

Definition at line 760 of file 3ddata.h.

#define RESAM_BLOCK_TYPE   3
 

Definition at line 759 of file 3ddata.h.

Referenced by LMAP_XNAME(), LMAP_YNAME(), and LMAP_ZNAME().

#define RESAM_CUBIC_STR   "Cubic Interpolation"
 

Definition at line 757 of file 3ddata.h.

#define RESAM_CUBIC_TYPE   2
 

Definition at line 756 of file 3ddata.h.

Referenced by LMAP_XNAME(), LMAP_YNAME(), and LMAP_ZNAME().

#define RESAM_LINEAR_STR   "Linear Interpolation"
 

Definition at line 754 of file 3ddata.h.

#define RESAM_LINEAR_TYPE   1
 

Definition at line 753 of file 3ddata.h.

Referenced by LMAP_XNAME(), LMAP_YNAME(), and LMAP_ZNAME().

#define RESAM_NN_STR   "Nearest Neighbor"
 

Definition at line 751 of file 3ddata.h.

#define RESAM_NN_TYPE   0
 

Definition at line 750 of file 3ddata.h.

Referenced by AFNI_dataset_slice(), AFNI_ttatlas_overlay(), LMAP_XNAME(), LMAP_YNAME(), LMAP_ZNAME(), RCREND_reload_dataset(), RCREND_reload_func_dset(), and THD_3dim_dataset_to_brick().

#define RETURNS_STRING   1
 

MCW_function_list possible bitmask flag

Definition at line 145 of file 3ddata.h.

Referenced by plot_graphs().

#define ROT3 a,
b,
c,
na,
nb,
nc       ((na)=(b),(nb)=(c),(nc)=(a))
 

rotate the three numbers (a,b,c) to (b,c,a) into (na,nb,nc)

Definition at line 3432 of file 3ddata.h.

#define ROTGEN_WARP th,
ff,
aa,
bb   
 

Value:

( tempA_warp.rig_bod.type       = WARP_AFFINE_TYPE ,                 \
     tempA_warp.rig_bod.resam_type = RESAM_NN_TYPE ,                    \
     tempA_warp.rig_bod.warp.type  = MAPPING_LINEAR_TYPE ,              \
     LOAD_ROTGEN_MAT(tempA_warp.rig_bod.warp.mfor, th,ff,aa,bb) ,       \
     LOAD_ROTGEN_MAT(tempA_warp.rig_bod.warp.mbac,-th,ff,aa,bb) ,       \
     LOAD_FVEC3(     tempA_warp.rig_bod.warp.bvec,     0,    0,    0 ) ,\
     LOAD_FVEC3(     tempA_warp.rig_bod.warp.svec,     0,    0,    0 ) ,\
     LOAD_FVEC3(     tempA_warp.rig_bod.warp.bot , -9999,-9999,-9999 ) ,\
     LOAD_FVEC3(     tempA_warp.rig_bod.warp.top ,  9999, 9999, 9999 ) ,\
     tempA_warp )
Return values is a warp of angle th about axis ff, in aa-bb plane.

Definition at line 858 of file 3ddata.h.

#define ROTX_WARP th       ROTGEN_WARP(th,0,1,2)
 

Definition at line 870 of file 3ddata.h.

#define ROTY_WARP th       ROTGEN_WARP(th,1,2,0)
 

Definition at line 871 of file 3ddata.h.

#define ROTZ_WARP th       ROTGEN_WARP(th,2,0,1)
 

Definition at line 872 of file 3ddata.h.

#define SARR_NUM ss       ((ss)->num)
 

Return number of strings stored in dynamic string array ss.

Definition at line 290 of file 3ddata.h.

Referenced by MCW_choose_multi_editable_strlist(), MCW_stradd_CB(), THD_get_all_executables(), and THD_getpathprogs().

#define SARR_STRING ss,
qq       ((ss)->ar[(qq)])
 

Return pointer to qq-th string in dynamic string array ss.

Definition at line 286 of file 3ddata.h.

Referenced by MCW_choose_multi_editable_strlist(), and MCW_stradd_CB().

#define SBFLAG_FACTOR   (1<<1)
 

Definition at line 3916 of file 3ddata.h.

Referenced by THD_subbrick_to_niml().

#define SBFLAG_INDEX   (1<<0)
 

Definition at line 3915 of file 3ddata.h.

Referenced by main(), SUMA_SendDset_Afni(), and THD_subbrick_to_niml().

#define SBFLAG_STATCODE   (1<<2)
 

Definition at line 3917 of file 3ddata.h.

#define SESSION_HAS_SUMA ss   
 

Value:

( (ss)!=NULL           &&  \
                               (ss)->su_surf!=NULL  &&  \
                               (ss)->su_num > 0        )
Determine if session has SUMA surface data attached.

Definition at line 2878 of file 3ddata.h.

Referenced by AFNI_brick_to_mri(), AFNI_imag_pop_CB(), AFNI_process_plugout(), AFNI_setup_viewing(), and AFNI_sumato_CB().

#define SESSION_TYPE   97
 

Definition at line 2831 of file 3ddata.h.

Referenced by AFNI_read_inputs(), and THD_init_session().

#define SESSIONLIST_TYPE   107
 

Definition at line 2882 of file 3ddata.h.

Referenced by AFNI_read_inputs().

#define SORT_3DARR name   
 

Value:

if( (name) != NULL && (name)->num > 1 ){                            \
      int iid , jjd ; THD_3dim_dataset * dt ;                          \
      for( iid=0 ; iid < (name)->num ; iid++ ){                        \
         for( jjd=1 ; jjd < (name)->num ; jjd++ ){                     \
            if( !DSET_ORDERED( (name)->ar[jjd-1] , (name)->ar[jjd] ) ) \
               DSET_SWAP( (name)->ar[jjd-1] , (name)->ar[jjd] ) ;      \
   }}}
Sort an AFNI dataset array

Definition at line 2819 of file 3ddata.h.

Referenced by THD_array_3dim_from_block().

#define STATISTICS_TYPE   17
 

Definition at line 1408 of file 3ddata.h.

Referenced by AFNI_copy_statistics(), THD_3dim_from_block(), THD_datablock_apply_atr(), THD_load_statistics(), THD_setup_mastery(), THD_update_one_bstat(), and THD_update_statistics().

#define STORAGE_BY_1D   8
 

Definition at line 920 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_1D(), THD_load_datablock(), and THD_open_1D().

#define STORAGE_BY_3D   9
 

Definition at line 921 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_3D(), THD_load_datablock(), and THD_open_3D().

#define STORAGE_BY_ANALYZE   5
 

Definition at line 917 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_analyze(), THD_load_datablock(), and THD_open_analyze().

#define STORAGE_BY_BRICK   2
 

Definition at line 914 of file 3ddata.h.

Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), EDIT_empty_copy(), main(), r_fill_resampled_data_brick(), T3D_read_images(), THD_copy_dset_subs(), THD_datablock_from_atr(), THD_dataset_info(), THD_load_datablock(), and THD_write_datablock().

#define STORAGE_BY_CTFMRI   6
 

Definition at line 918 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_ctfmri(), THD_load_datablock(), and THD_open_ctfmri().

#define STORAGE_BY_CTFSAM   7
 

Definition at line 919 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_ctfsam(), THD_load_datablock(), and THD_open_ctfsam().

#define STORAGE_BY_MINC   3
 

Definition at line 915 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_datablock(), THD_load_minc(), and THD_open_minc().

#define STORAGE_BY_MPEG   11
 

Definition at line 923 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_datablock(), THD_load_mpeg(), and THD_open_mpeg().

#define STORAGE_BY_NIFTI   10
 

Definition at line 922 of file 3ddata.h.

Referenced by THD_dataset_info(), THD_load_datablock(), THD_load_nifti(), and THD_open_nifti().

#define STORAGE_BY_VOLUMES   4
 

Definition at line 916 of file 3ddata.h.

Referenced by THD_datablock_from_atr(), THD_dataset_info(), THD_load_datablock(), and THD_write_datablock().

#define STORAGE_UNDEFINED   0
 

Definition at line 913 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), adwarp_refashion_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), AFNI_refashion_dataset(), duplicate_dataset(), EDIT_empty_datablock(), EDIT_wod_copy(), THD_datablock_from_atr(), THD_init_one_datablock(), THD_load_datablock(), and THD_write_datablock().

#define STRING_HAS_SUFFIX ss,
suf   
 

Value:

((ss != NULL) && (suf != NULL) &&            \
   (strlen(ss) >= strlen(suf))   &&            \
   (strcmp(ss+strlen(ss)-strlen(suf),suf) == 0))
Macro to check if string ss ends in string suf.

Definition at line 60 of file 3ddata.h.

Referenced by AFNI_drive_save_jpeg(), EDIT_dset_items(), ISQ_save_jpeg(), main(), mri_write_pnm(), THD_fetch_dataset(), THD_open_dataset(), THD_open_one_dataset(), THD_read_all_atr(), THD_write_1D(), and THD_write_3dim_dataset().

#define SUCCESS   1
 

Definition at line 110 of file 3ddata.h.

Referenced by THD_read_all_atr(), and THD_write_atr().

#define THD_DEFAULT_LABEL   "Viggo!"
 

Default label for a dataset.

Labels aren't really used anymore, since the stupid users didn't like them

Definition at line 95 of file 3ddata.h.

Referenced by THD_3dim_from_block().

#define THD_MAX_CHOICES   THD_MAX_SESSION_SIZE
 

Definition at line 105 of file 3ddata.h.

Referenced by AFNI_choose_dataset_CB().

#define THD_MAX_FILECODE   (THD_MAX_PREFIX+THD_MAX_VIEWCODE)
 

Max length of a dataset filecode (prefix+view).

Definition at line 89 of file 3ddata.h.

#define THD_MAX_LABEL   38
 

Max length of a dataset label.

Definition at line 73 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), duplicate_dataset(), EDIT_dset_items(), EDIT_empty_copy(), main(), MRG_read_opts(), T3D_create_widgets(), T3D_initialize_user_data(), T3D_save_file_CB(), T3D_widgets_to_data(), THD_3dim_from_block(), and TT_read_opts().

#define THD_MAX_MARKSET   5
 

Definition at line 107 of file 3ddata.h.

#define THD_MAX_NAME   256
 

Max length of a "name" of a file, or stuff like that.

Definition at line 69 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_do_many_writes(), AFNI_drive_open_graph_1D(), AFNI_drive_open_graph_xy(), AFNI_drive_purge_memory(), AFNI_drive_switch_anatomy(), AFNI_drive_switch_function(), AFNI_drive_switch_session(), AFNI_find_jpegs(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_marks_transform_CB(), AFNI_read_images(), AFNI_read_inputs(), AFNI_rescan_CB(), AFNI_set_window_titles(), AFNI_update_surface_widgets(), AFNI_write_many_dataset_CB(), B2F_read_opts(), BFIT_main(), BUCK_read_opts(), CALC_read_opts(), check_for_valid_inputs(), check_one_output_file(), CORREL_main(), do_xrestore_stuff(), DRAW_choose_CB(), DT_read_opts(), duplicate_dataset(), EDIT_dset_items(), EDIT_empty_copy(), ENV_sesstrail(), EX_read_opts(), get_line_opt(), get_options(), HISTO_main(), initialize_glt_options(), initialize_stim_options(), main(), make_PLUGIN_dataset_link(), markov_array(), MRG_read_opts(), mri_warp3d_align_one(), NLFIT_get_many_MODELs(), NOTES_choose_CB(), NUD_choose_CB(), patch_PLUGIN_dataset_links(), PLUG_choose_dataset_CB(), PLUG_finalize_dataset_CB(), PLUG_get_many_plugins(), process_subbrick(), RCREND_choose_av_CB(), RCREND_choose_CB(), RCREND_finalize_dset_CB(), RCREND_finalize_func_CB(), RCREND_read_states(), read_input_data(), read_one_time_series(), read_options(), read_table(), read_time_series(), REND_choose_av_CB(), REND_choose_CB(), REND_finalize_dset_CB(), REND_finalize_func_CB(), REND_read_states(), SC_read_opts(), SCAT_main(), T3D_anatomy_parent_CB(), T3D_check_data(), T3D_create_widgets(), T3D_geometry_parent_CB(), T3D_initialize_user_data(), T3D_read_images(), T3D_save_file_CB(), T3D_setup_stat_aux(), T3D_widgets_to_data(), TCAT_read_opts(), THD_3dim_from_block(), THD_datablock_apply_atr(), THD_datablock_from_atr(), THD_get_many_timeseries(), THD_getpathprogs(), THD_init_alldir_datablocks(), THD_init_diskptr_names(), THD_init_one_datablock(), THD_init_prefix_datablocks(), THD_init_session(), THD_open_3D(), THD_open_analyze(), THD_open_dataset(), THD_open_one_dataset(), THD_read_all_atr(), THD_rename_dataset_files(), THD_write_1D(), TT_load_atlas(), TT_read_opts(), write_bucket_data(), write_results(), write_table(), and write_ts_array().

#define THD_MAX_NUM_SESSION   80
 

Max number of directories.

Definition at line 103 of file 3ddata.h.

Referenced by AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_read_sess_CB(), and AFNI_syntax().

#define THD_MAX_PREFIX   (127+1)
 

Max length of a dataset prefix.

Definition at line 77 of file 3ddata.h.

Referenced by AFNI_choose_dataset_CB(), AFNI_fimmer_compute(), B2F_read_opts(), BUCK_read_opts(), CALC_read_opts(), DRAW_copy_dset(), DT_read_opts(), EX_read_opts(), get_options(), main(), MRG_read_opts(), PC_read_opts(), PLUGIN_init(), read_options(), RT_check_info(), RT_fim_recurse(), RT_process_info(), RT_start_dataset(), SC_read_opts(), T3D_create_widgets(), T3D_initialize_user_data(), TCAT_read_opts(), THD_init_diskptr_names(), THD_open_1D(), THD_open_3D(), THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), TT_read_opts(), UC_read_opts(), and ZCAT_read_opts().

#define THD_MAX_RANK   3
 

Definition at line 892 of file 3ddata.h.

Referenced by THD_datablock_from_atr().

#define THD_MAX_RANK_EVER   5
 

Definition at line 894 of file 3ddata.h.

#define THD_MAX_SESSION_SIZE   4096
 

Max num datasets per session.

Definition at line 99 of file 3ddata.h.

Referenced by AFNI_append_sessions(), AFNI_fimmer_execute(), AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), AFNI_syntax(), PLUTO_add_dset(), process_NIML_AFNI_dataset(), process_NIML_Node_ROI(), RT_tell_afni_one(), THD_init_session(), and THD_order_session().

#define THD_MAX_SUFFIX   (4+1)
 

Max length of a dataset suffix (BRIK, etc).

Definition at line 85 of file 3ddata.h.

#define THD_MAX_VIEWCODE   (4+1)
 

Max length of a dataset view code (+orig, etc).

Definition at line 81 of file 3ddata.h.

Referenced by THD_init_diskptr_names().

#define THD_MIN_RANK   3
 

Definition at line 893 of file 3ddata.h.

Referenced by THD_datablock_from_atr().

#define THD_null_datablock_auxdata blk   
 

Value:

( (blk)->brick_lab      = NULL , \
                                          (blk)->brick_keywords = NULL , \
                                          (blk)->brick_statcode = NULL , \
                                          (blk)->brick_stataux  = NULL  )
Initialize all sub-bricks auxiliary data to nothing.

Definition at line 1136 of file 3ddata.h.

Referenced by AFNI_init_warp(), EDIT_empty_copy(), EDIT_empty_datablock(), and T3D_read_images().

#define THD_set_string_atr blk,
name,
str       THD_set_char_atr( (blk) , (name) , strlen(str)+1 , (str) )
 

Macro to set a string attribute from a C string (vs. a char array).

Definition at line 3132 of file 3ddata.h.

Referenced by DRAW_attach_dtable(), main(), THD_anonymize_dset(), THD_dblkatr_from_niml(), THD_set_dataset_attributes(), THD_write_datablock(), tross_Add_Note(), tross_Append_History(), tross_Copy_History(), tross_Replace_History(), and tross_Store_Note().

#define TIMEAXIS_TYPE   907
 

Definition at line 1353 of file 3ddata.h.

Referenced by EDIT_dset_items(), T3D_save_file_CB(), and THD_3dim_from_block().

#define TM_IXY   2
 

Definition at line 3588 of file 3ddata.h.

Referenced by create_Tmask_byte(), and create_Tmask_rgba().

#define TM_IYZ   0
 

Definition at line 3589 of file 3ddata.h.

Referenced by create_Tmask_byte(), and create_Tmask_rgba().

#define TM_IZX   1
 

Definition at line 3590 of file 3ddata.h.

Referenced by create_Tmask_byte(), and create_Tmask_rgba().

#define TM_XLINE tm,
i       (tm==NULL || tm->mask[TM_IYZ][i])
 

Definition at line 3605 of file 3ddata.h.

Referenced by apply_xshear(), flip_xy(), and flip_xz().

#define TM_YLINE tm,
i       (tm==NULL || tm->mask[TM_IZX][i])
 

Definition at line 3604 of file 3ddata.h.

Referenced by apply_yshear(), and flip_yz().

#define TM_ZLINE tm,
i       (tm==NULL || tm->mask[TM_IXY][i])
 

Definition at line 3603 of file 3ddata.h.

Referenced by apply_zshear().

#define tross_Erase_History ds       THD_erase_one_atr((ds)->dblk,"HISTORY_NOTE")
 

Definition at line 3835 of file 3ddata.h.

#define TS_HELP_STRING
 

Help string to explain 1D column and row selection. [01 May 2003]

Definition at line 3252 of file 3ddata.h.

Referenced by main().

#define TT_ATLAS_NZ_BIG   151
 

Definition at line 3875 of file 3ddata.h.

#define TT_ATLAS_NZ_SMALL   141
 

Definition at line 3874 of file 3ddata.h.

#define TT_retrieve_atlas_nz nz   
 

Value:

Definition at line 3877 of file 3ddata.h.

Referenced by AFNI_ttatlas_overlay(), RCREND_overlay_ttatlas(), and REND_overlay_ttatlas().

#define TWO_ONE x,
y       x ## y
 

First part of TWO_TWO macro.

Definition at line 169 of file 3ddata.h.

#define TWO_TWO x,
y       TWO_ONE(x,y)
 

Combine two interpreted tokens into one using TWO_TWO.

Definition at line 173 of file 3ddata.h.

Referenced by AFNI_dataset_slice().

#define TWOGIG   2147000000
 

Definition at line 2748 of file 3ddata.h.

#define UNITS_HZ_TYPE   77003
 

Definition at line 1357 of file 3ddata.h.

Referenced by Fourier_Filter_Driver(), main(), POWER_main(), PRIC_main(), RIC_CalcCoeffAB(), RIC_CorrectDataset(), and T3D_initialize_user_data().

#define UNITS_MSEC_TYPE   77001
 

Definition at line 1355 of file 3ddata.h.

Referenced by calculate_results(), FD_brick_to_series(), Fourier_Filter_Driver(), get_options(), get_time(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), PLUTO_4D_to_nothing(), populate_nifti_image(), POWER_main(), PRIC_main(), read_input_data(), RIC_CalcCoeffAB(), RIC_CorrectDataset(), T3D_initialize_user_data(), THD_3dim_from_block(), THD_extract_many_series(), THD_extract_series(), and THD_write_1D().

#define UNITS_SEC_TYPE   77002
 

Definition at line 1356 of file 3ddata.h.

Referenced by AFNI_read_inputs(), Fourier_Filter_Driver(), main(), POWER_main(), PRIC_main(), RIC_CalcCoeffAB(), RIC_CorrectDataset(), RT_start_dataset(), T3D_initialize_user_data(), THD_dataset_tshift(), THD_open_1D(), THD_open_3D(), THD_open_analyze(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), and THD_open_tcat().

#define UNITS_TYPE_LABEL uu       UNITS_TYPE_labelstring[(uu)-UNITS_MSEC_TYPE]
 

Return a string for the units of the uu-th time unit type.

Definition at line 1363 of file 3ddata.h.

Referenced by main(), T3D_create_widgets(), and THD_dataset_info().

#define VIEW_ACPCALIGNED_CODE   "acpc"
 

Definition at line 1551 of file 3ddata.h.

Referenced by Syntax().

#define VIEW_ACPCALIGNED_STR   "AC-PC Aligned"
 

Definition at line 1550 of file 3ddata.h.

#define VIEW_ACPCALIGNED_TYPE   1
 

Definition at line 1549 of file 3ddata.h.

Referenced by AFNI_drive_set_view(), AFNI_init_warp(), AFNI_make_descendants(), and SUMA_BrainVoyager_Read_vmr().

#define VIEW_ORIGINAL_CODE   "orig"
 

Definition at line 1547 of file 3ddata.h.

Referenced by Syntax().

#define VIEW_ORIGINAL_STR   "Original View"
 

Definition at line 1546 of file 3ddata.h.

Referenced by T3D_create_widgets().

#define VIEW_ORIGINAL_TYPE   0
 

Definition at line 1545 of file 3ddata.h.

Referenced by AFNI_andersonville(), AFNI_can_transform_vector(), AFNI_drive_set_view(), AFNI_force_adoption(), AFNI_make_descendants(), AFNI_make_wid2(), AFNI_marks_transform_CB(), AFNI_read_inputs(), AFNI_transform_vector(), EDIT_empty_copy(), EDIT_empty_datablock(), main(), PLUG_choose_dataset_CB(), RT_start_dataset(), RT_tell_afni_one(), SUMA_BrainVoyager_Read_vmr(), SUMA_OpenDX_Read_CruiseVolHead(), T3D_initialize_user_data(), T3D_save_file_CB(), THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), THD_open_minc(), THD_open_mpeg(), and THD_open_nifti().

#define VIEW_REGISTERED_CODE   "rgst"
 

Definition at line 1559 of file 3ddata.h.

#define VIEW_REGISTERED_STR   "Registered View"
 

Definition at line 1558 of file 3ddata.h.

#define VIEW_REGISTERED_TYPE   3
 

Definition at line 1557 of file 3ddata.h.

#define VIEW_TALAIRACH_CODE   "tlrc"
 

Definition at line 1555 of file 3ddata.h.

Referenced by Syntax().

#define VIEW_TALAIRACH_STR   "Talairach View"
 

Definition at line 1554 of file 3ddata.h.

#define VIEW_TALAIRACH_TYPE   2
 

Definition at line 1553 of file 3ddata.h.

Referenced by AFNI_define_CB(), AFNI_drive_set_view(), AFNI_imag_pop_CB(), AFNI_mnito_CB(), AFNI_overlay(), AFNI_process_plugout(), AFNI_see_ttatlas_CB(), AFNI_setup_viewing(), AFNI_talto_CB(), AFNI_ttatlas_query(), DRAW_ttatlas_CB(), main(), populate_nifti_image(), SUMA_BrainVoyager_Read_vmr(), THD_open_analyze(), THD_open_minc(), THD_open_nifti(), THD_write_minc(), and TTget_recv().

#define W_LAI   7
 

Definition at line 788 of file 3ddata.h.

#define W_LAS   1
 

Definition at line 782 of file 3ddata.h.

#define W_LMI   9
 

Definition at line 790 of file 3ddata.h.

#define W_LMS   3
 

Definition at line 784 of file 3ddata.h.

#define W_LPI   11
 

Definition at line 792 of file 3ddata.h.

#define W_LPS   5
 

Definition at line 786 of file 3ddata.h.

#define W_RAI   6
 

Definition at line 787 of file 3ddata.h.

#define W_RAS   0
 

Definition at line 781 of file 3ddata.h.

#define W_RMI   8
 

Definition at line 789 of file 3ddata.h.

#define W_RMS   2
 

Definition at line 783 of file 3ddata.h.

#define W_RPI   10
 

Definition at line 791 of file 3ddata.h.

#define W_RPS   4
 

Definition at line 785 of file 3ddata.h.

#define WARP3D_GRIDMASK   7
 

Definition at line 3784 of file 3ddata.h.

Referenced by THD_warp3D().

#define WARP3D_NEWDSET   2
 

Definition at line 3783 of file 3ddata.h.

Referenced by main(), and THD_warp3D().

#define WARP3D_NEWGRID   1
 

Definition at line 3782 of file 3ddata.h.

Referenced by main(), and THD_warp3D().

#define WARP_AFFINE_SIZE   (MAPPING_LINEAR_FSIZE)
 

Definition at line 822 of file 3ddata.h.

#define WARP_AFFINE_STR   "WARP_AFFINE"
 

Definition at line 736 of file 3ddata.h.

#define WARP_AFFINE_TYPE   0
 

Definition at line 735 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_backward_warp_vector(), AFNI_concatenate_warp(), AFNI_dataset_slice(), AFNI_follower_dataset(), AFNI_forward_warp_vector(), AFNI_init_warp(), AFNI_make_affwarp_12(), AFNI_make_voxwarp(), AFNI_make_warp(), main(), SUMA_AFNI_forward_warp_xyz(), THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define WARP_TALAIRACH_12_SIZE   (12*MAPPING_LINEAR_FSIZE)
 

Definition at line 794 of file 3ddata.h.

Referenced by THD_set_dataset_attributes().

#define WARP_TALAIRACH_12_STR   "WARP_TALAIRACH_12"
 

Definition at line 739 of file 3ddata.h.

#define WARP_TALAIRACH_12_TYPE   1
 

Definition at line 738 of file 3ddata.h.

Referenced by adwarp_follower_dataset(), AFNI_backward_warp_vector(), AFNI_concatenate_warp(), AFNI_dataset_slice(), AFNI_follower_dataset(), AFNI_forward_warp_vector(), AFNI_init_warp(), AFNI_make_voxwarp(), AFNI_make_warp(), SUMA_AFNI_forward_warp_xyz(), THD_3dim_from_block(), THD_datablock_apply_atr(), and THD_set_dataset_attributes().

#define XTARR_IC name,
i       ((name)->ic[i])
 

Definition at line 256 of file 3ddata.h.

Referenced by AFNI_finalize_read_Web_CB(), AFNI_read_inputs(), and THD_fetch_many_datasets().

#define XTARR_NUM name       ((name)->num)
 

Number of good entries in a dynamic XtPointer array.

Definition at line 250 of file 3ddata.h.

Referenced by THD_fetch_many_datasets().

#define XTARR_XT name,
i       ((name)->ar[i])
 

i-th entry in a dynamic XtPointer array.

Definition at line 254 of file 3ddata.h.

Referenced by AFNI_finalize_read_Web_CB(), and AFNI_read_inputs().

#define ZBLOCK   126
 

Definition at line 466 of file 3ddata.h.

Referenced by THD_nimlize_dsetatr(), THD_unzblock(), and THD_zblock().

#define ZERO_IDCODE id       ((id).str[0] = (id).date[0] = '\0')
 

Zero out the ID code.

Definition at line 1490 of file 3ddata.h.

Referenced by AFNI_init_warp(), AFNI_read_images(), AFNI_rescan_session_OLD(), DSET2_dset_recv(), DSETN_main(), EDIT_empty_copy(), main(), make_PLUGIN_dataset_link(), NUD_main(), PLUG_choose_dataset_CB(), PLUG_fillin_values(), PLUGIN_init(), RCREND_read_states(), RCREND_widgets_to_state(), REND_read_states(), REND_widgets_to_state(), set_global_dsets_from_ids(), T3D_initialize_user_data(), T3D_save_file_CB(), THD_3dim_from_block(), and write_results().

#define ZERO_STAT_AUX ds   
 

Value:

do{ int is ; for( is=0 ; is < MAX_STAT_AUX ; is++ )  \
                 (ds)->stat_aux[is] = 0.0 ; } while(0)
Clear the global stat_aux data in a dataset.

Definition at line 2637 of file 3ddata.h.

Referenced by AFNI_read_images(), EDIT_empty_copy(), T3D_read_images(), and THD_3dim_from_block().

#define ZPAD_EMPTY   (1<<0)
 

Definition at line 3761 of file 3ddata.h.

Referenced by main(), and THD_zeropad().

#define ZPAD_MM   (1<<2)
 

Definition at line 3763 of file 3ddata.h.

Referenced by main(), T3D_save_file_CB(), and THD_zeropad().

#define ZPAD_PURGE   (1<<1)
 

Definition at line 3762 of file 3ddata.h.

Referenced by main(), THD_warp3D(), THD_zeropad(), and ZPAD_main().


Typedef Documentation

typedef struct FD_brick FD_brick
 

This type is to hold information needed for the rapid extraction of slices from an AFNI dataset (THD_3dim_dataset struct).

It exists primarily as a historical artifact. The earliest version of AFNI was to be called FD3, as a successor to FD2. The FD_brick was conceived as part of FD3. However, FD3 morphed into AFNI within a few weeks, but by then I didn't want to throw away the code that had already been structured around this (primarily the imseq.c stuff).

typedef float float_func()
 

Generic function type returning float.

Definition at line 128 of file 3ddata.h.

Referenced by ISQ_slice_proj_CB().

typedef void generic_func()
 

Generic function type returning void.

Definition at line 124 of file 3ddata.h.

Referenced by AFNI_faceup(), AFNI_fimmer_compute(), AFNI_register_fimfunc(), AFNI_register_nD_func_init(), AFNI_register_nD_function(), AIVVV_imseq_popup(), ENV_add_numeric(), ENV_add_string(), EXP0D_init(), F1D_init(), F2D_init(), MAIN_workprocess(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), mri_rgb_transform_nD(), PLUGIN_init(), PLUTO_4D_to_nothing(), PLUTO_4D_to_typed_fbuc(), PLUTO_4D_to_typed_fim(), PLUTO_4D_to_typed_fith(), PLUTO_imseq_popim(), PLUTO_imseq_popup(), PLUTO_imseq_rekill(), PLUTO_register_timeout(), and THD_set_freeup().

typedef struct THD_3dim_dataset THD_3dim_dataset
 

One AFNI dataset structure. Most elements are accessed via macros, and should only be changed via EDIT_dset_items().

typedef struct THD_3dim_dataset_array THD_3dim_dataset_array
 

A dynamic array type for AFNI datasets.

This is used when collecting all the datasets in a directory into a THD_session.


Function Documentation

THD_linear_mapping* AFNI_concatenate_lmap THD_linear_mapping  ,
THD_linear_mapping  
 

Definition at line 265 of file thd_warps.c.

References ADD_FVEC3, THD_linear_mapping::bot, THD_linear_mapping::bvec, MAPPING_LINEAR_TYPE, MAT_INV, MAT_MUL, MATVEC, THD_linear_mapping::mbac, THD_linear_mapping::mfor, myXtNew, NEGATE_FVEC3, THD_linear_mapping::svec, THD_linear_mapping::top, and THD_linear_mapping::type.

Referenced by AFNI_concatenate_warp().

00267 {
00268    THD_linear_mapping * map_out ;
00269    THD_fvec3 tvec ;
00270 
00271    /* make a new linear mapping */
00272 
00273    map_out = myXtNew(THD_linear_mapping) ;
00274    map_out->type = MAPPING_LINEAR_TYPE ;
00275 
00276    /* matrix */
00277 
00278    map_out->mfor = MAT_MUL( map_2->mfor , map_1->mfor ) ;
00279    map_out->mbac = MAT_INV( map_out->mfor ) ;
00280 
00281    /* vector */
00282 
00283    tvec          = MATVEC( map_2->mfor , map_1->bvec ) ;
00284    map_out->bvec = ADD_FVEC3( tvec , map_2->bvec ) ;
00285    map_out->svec = MATVEC( map_out->mbac , map_out->bvec ) ;
00286    NEGATE_FVEC3(map_out->svec) ;
00287 
00288    map_out->bot  = map_2->bot ;
00289    map_out->top  = map_2->top ;
00290 
00291    return map_out ;
00292 }

void AFNI_concatenate_warp THD_warp  ,
THD_warp  
 

Definition at line 193 of file thd_warps.c.

References AFNI_concatenate_lmap(), myXtFree, myXtNew, THD_warp::rig_bod, THD_warp::tal_12, THD_warp::type, THD_talairach_12_warp::type, THD_affine_warp::warp, THD_talairach_12_warp::warp, WARP_AFFINE_TYPE, and WARP_TALAIRACH_12_TYPE.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), and THD_init_session().

00194 {
00195    THD_linear_mapping * prior_map , * new_map ;
00196 
00197    if( warp_in == NULL || warp_prior == NULL ) return ;
00198 
00199    switch( warp_in->type + 100*warp_prior->type ){
00200 
00201       default:
00202          warp_in->type = -1 ;  /* set error flag! */
00203          return ;
00204 
00205       /*-- 2 affine warps ==> a new affine warp --*/
00206 
00207       case WARP_AFFINE_TYPE + 100*WARP_AFFINE_TYPE:{
00208          prior_map = &(warp_prior->rig_bod.warp) ;
00209          new_map = AFNI_concatenate_lmap(
00210                       &(warp_in->rig_bod.warp) , prior_map ) ;
00211 
00212          warp_in->rig_bod.warp = *new_map ;  /* write over input warp */
00213          myXtFree( new_map ) ;
00214       }
00215       break ;
00216 
00217       /*--- Talairach preceeded by affine ==> new Talairach --*/
00218 
00219       case WARP_TALAIRACH_12_TYPE + 100*WARP_AFFINE_TYPE:{
00220          int iw ;
00221          prior_map = &(warp_prior->rig_bod.warp) ;
00222          for( iw=0 ; iw < 12 ; iw++ ){
00223 
00224             new_map = AFNI_concatenate_lmap(
00225                          &(warp_in->tal_12.warp[iw]) , prior_map ) ;
00226 
00227             warp_in->tal_12.warp[iw] = *new_map ;  /* write over input warp */
00228             myXtFree( new_map ) ;
00229          }
00230       }
00231       break ;
00232 
00233       /*-- affine preceeded by Talairach ==> new Talairach
00234            [this case is not currently used, since there are no warps
00235             AFTER a Talairach warp, but it may be useful in the future]
00236                                         -- RWCox, November 1994 A.D. --*/
00237 
00238       case WARP_AFFINE_TYPE + 100*WARP_TALAIRACH_12_TYPE:{
00239          int iw ;
00240          THD_talairach_12_warp * new_warp = myXtNew( THD_talairach_12_warp ) ;
00241 
00242          new_warp->type = WARP_TALAIRACH_12_TYPE ;
00243          for( iw=0 ; iw < 12 ; iw++ ){
00244             prior_map = &(warp_prior->tal_12.warp[iw]) ;
00245             new_map   = AFNI_concatenate_lmap(
00246                           &(warp_in->rig_bod.warp) , prior_map ) ;
00247             new_warp->warp[iw] = *new_map ;
00248             myXtFree( new_map ) ;
00249          }
00250 
00251          warp_in->tal_12 = *new_warp ;  /* write over input warp */
00252          myXtFree( new_warp ) ;
00253       }
00254       break ;
00255 
00256    }  /* end of switch on warp types */
00257 
00258    return ;
00259 }

int AFNI_logger char *   ,
int   ,
char **   
 

Definition at line 40 of file afni_logger.c.

References AFMALL, AFNI_sleep(), AFNI_yesenv(), argc, fll, free, getenv(), LOCK_file, LOGFILE, THD_filesize(), tross_commandline(), tross_datetime(), and UNLOCK_file.

Referenced by F3D_initialize_user_data(), get_inputs(), get_line_opt(), get_options(), initialize_program(), and main().

00041 {
00042    char *cline, *cdate , *eh , *fn , *logfile=LOGFILE ;
00043    FILE *fp ;
00044    int ll ; unsigned long fll ;
00045 
00046    if( pname == NULL || pname[0] == '\0' ) return -1 ;
00047    eh = getenv("HOME") ; if( eh == NULL )  return -1 ;
00048    if( AFNI_yesenv("AFNI_DONT_LOGFILE") )  return -1 ;
00049    if( argc > 1 ) cline = tross_commandline( pname , argc , argv ) ;
00050    else           cline = strdup(pname) ;
00051    if( cline == NULL ) return -1 ;
00052    cdate = tross_datetime() ;
00053    fn = AFMALL(char,  strlen(eh)+strlen(logfile)+8) ;
00054    strcpy(fn,eh) ; strcat(fn,"/") ; strcat(fn,logfile) ;
00055    if( (fll=THD_filesize(fn)) > 100000000 )   /* 01 Jun 2005: for Kevin */
00056      fprintf(stderr,"++ WARNING: file %s is now %lu bytes long!\n",fn,fll) ;
00057    fp = fopen(fn,"a") ;
00058    if( fp == NULL ){ free(fn); free(cdate); free(cline); return -1; }
00059    ll = LOCK_file(fp) ;
00060    if( ll ){
00061 #if 0
00062      fprintf(stderr,"%s: LOCKED\n",cline);
00063 #endif
00064      ll = strlen(pname) ; if( ll > 11 ) ll = 11 ;
00065      AFNI_sleep(ll) ; ll = LOCK_file(fp) ;
00066      if( ll ){ fclose(fp); free(fn); free(cdate); free(cline); return -1; }
00067    }
00068    fseek(fp,0,SEEK_END) ;
00069    fprintf(fp,"[%s] %s\n",cdate,cline) ;
00070    UNLOCK_file(fp) ; fclose(fp) ;
00071    free(fn); free(cdate); free(cline) ; return 0;
00072 }

THD_warp* AFNI_make_affwarp_12 float    a11,
float    a12,
float    a13,
float    s1,
float    a21,
float    a22,
float    a23,
float    s2,
float    a31,
float    a32,
float    a33,
float    s3
 

Make an affine warp from 12 input numbers:

  • [ a11 a12 a13 ] [ s1 ]
  • x_map = [ a21 a22 a23 ] x_in + [ s2 ]
  • [ a31 a32 a33 ] [ s3 ]
27 Aug 2002 - RWCox. ----------------------------------------------------------------------------

Definition at line 303 of file thd_warps.c.

References THD_linear_mapping::bvec, LOAD_FVEC3, LOAD_INVERSE_LMAP, LOAD_MAT, MAPPING_LINEAR_TYPE, MAT_DET, MAT_FNORM, THD_linear_mapping::mfor, myXtNew, THD_warp::rig_bod, s2, THD_warp::type, THD_linear_mapping::type, THD_affine_warp::warp, and WARP_AFFINE_TYPE.

Referenced by AFNI_make_affwarp_mat(), AFNI_make_affwarp_matvec(), and THD_init_session().

00306 {
00307    THD_warp *warp ;
00308    THD_linear_mapping map ;
00309    float dd , nn ;
00310 
00311    warp       = myXtNew( THD_warp ) ;
00312    warp->type = WARP_AFFINE_TYPE ;
00313 
00314    map.type = MAPPING_LINEAR_TYPE ;
00315 
00316    LOAD_MAT(map.mfor,a11,a12,a13,a21,a22,a23,a31,a32,a33) ;
00317    dd = MAT_DET(map.mfor) ; nn = MAT_FNORM(map.mfor) ;
00318    if( fabs(dd) < 1.e-5*nn*nn*nn ) return NULL ;  /* bad input */
00319    LOAD_FVEC3(map.bvec,-s1,-s2,-s3) ;
00320    LOAD_INVERSE_LMAP(map) ;
00321 
00322    warp->rig_bod.warp = map ;
00323 
00324    return warp ;
00325 }

THD_warp* AFNI_make_affwarp_mat THD_mat33   
 

Definition at line 329 of file thd_warps.c.

References AFNI_make_affwarp_12(), THD_mat33::mat, and mmm.

Referenced by THD_init_session().

00330 {
00331    return AFNI_make_affwarp_12( mmm.mat[0][0], mmm.mat[0][1], mmm.mat[0][2], 0.0 ,
00332                                 mmm.mat[1][0], mmm.mat[1][1], mmm.mat[1][2], 0.0 ,
00333                                 mmm.mat[2][0], mmm.mat[2][1], mmm.mat[2][2], 0.0  ) ;
00334 }

THD_warp* AFNI_make_affwarp_matvec THD_mat33   ,
THD_fvec3   
 

Definition at line 338 of file thd_warps.c.

References AFNI_make_affwarp_12(), THD_mat33::mat, mmm, and THD_fvec3::xyz.

00339 {
00340    return AFNI_make_affwarp_12( mmm.mat[0][0], mmm.mat[0][1], mmm.mat[0][2], vvv.xyz[0] ,
00341                                 mmm.mat[1][0], mmm.mat[1][1], mmm.mat[1][2], vvv.xyz[1] ,
00342                                 mmm.mat[2][0], mmm.mat[2][1], mmm.mat[2][2], vvv.xyz[2]  ) ;
00343 }

THD_linear_mapping* AFNI_make_voxmap THD_linear_mapping  ,
THD_dataxes  ,
THD_dataxes  
 

Definition at line 107 of file thd_warps.c.

References ADD_FVEC3, THD_linear_mapping::bvec, do_nothing, LOAD_DIAG_MAT, LOAD_FVEC3, MAPPING_LINEAR_TYPE, MAT_INV, MAT_MUL, MATVEC, THD_linear_mapping::mbac, THD_linear_mapping::mfor, myXtNew, NEGATE_FVEC3, SUB_FVEC3, THD_linear_mapping::svec, THD_dataxes::to_dicomm, TRANSPOSE_MAT, THD_linear_mapping::type, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_make_voxwarp().

00110 {
00111    THD_mat33 old_scale , old_3dmm_to_dicomm ,
00112              dd_trans  , new_scale , new_dicomm_to_3dmm ,
00113              mt ; /* temp matrix */
00114 
00115    THD_fvec3 dd_base , new_origin , old_origin , vt0,vt1,vt2 ;
00116 
00117    THD_linear_mapping * newmap ;
00118 
00119    /*--- set up the elements of the transformation ---*/
00120 
00121    dd_trans = inmap->mfor ;
00122 
00123    LOAD_DIAG_MAT( old_scale , old_daxes->xxdel ,
00124                               old_daxes->yydel ,
00125                               old_daxes->zzdel  ) ;
00126 
00127    LOAD_DIAG_MAT( new_scale , 1.0/new_daxes->xxdel ,     /* notice */
00128                               1.0/new_daxes->yydel ,     /* inversion */
00129                               1.0/new_daxes->zzdel  ) ;
00130 
00131    old_3dmm_to_dicomm = old_daxes->to_dicomm ;
00132    new_dicomm_to_3dmm = TRANSPOSE_MAT(new_daxes->to_dicomm) ; /* inversion */
00133 
00134    /* vector elements */
00135 
00136    dd_base = inmap->bvec ;                        /* in new dicomm */
00137 
00138    LOAD_FVEC3( new_origin , new_daxes->xxorg ,    /* in old 3dmm */
00139                             new_daxes->yyorg ,
00140                             new_daxes->zzorg  ) ;
00141 
00142    LOAD_FVEC3( old_origin , old_daxes->xxorg ,    /* in new 3dmm */
00143                             old_daxes->yyorg ,
00144                             old_daxes->zzorg  ) ;
00145 
00146    /* multiply the matrices together */
00147 
00148    mt = MAT_MUL( old_3dmm_to_dicomm , old_scale ) ;   do_nothing(0) ;
00149    mt = MAT_MUL( dd_trans , mt ) ;                    do_nothing(0) ;
00150    mt = MAT_MUL( new_dicomm_to_3dmm , mt ) ;          do_nothing(0) ;
00151    mt = MAT_MUL( new_scale , mt ) ;                   do_nothing(0) ;
00152 
00153    /* compute the new bvec */
00154 
00155    vt0 = MATVEC( old_3dmm_to_dicomm , old_origin ) ;
00156    vt0 = MATVEC( dd_trans , vt0 ) ;
00157    vt0 = MATVEC( new_dicomm_to_3dmm , vt0 ) ;
00158    vt0 = MATVEC( new_scale , vt0 ) ;
00159 
00160    vt1 = MATVEC( new_dicomm_to_3dmm , dd_base ) ;
00161    vt1 = MATVEC( new_scale , vt1 ) ;
00162 
00163    vt2 = MATVEC( new_scale , new_origin ) ;  /* want vt1 + vt2 - vt0 */
00164 
00165    vt2 = ADD_FVEC3( vt1 , vt2 ) ;
00166    vt2 = SUB_FVEC3( vt2 , vt0 ) ;
00167 
00168    /* make the output map */
00169 
00170    newmap = myXtNew( THD_linear_mapping ) ;
00171 
00172    newmap->type = MAPPING_LINEAR_TYPE ;
00173    newmap->mfor = mt ;
00174    newmap->mbac = MAT_INV(mt) ;
00175    newmap->bvec = vt2 ;
00176 
00177    newmap->svec = MATVEC(newmap->mbac,newmap->bvec) ;
00178    NEGATE_FVEC3(newmap->svec) ;
00179 
00180    return newmap ;
00181 }

THD_warp* AFNI_make_voxwarp THD_warp  ,
THD_3dim_dataset  ,
THD_3dim_dataset  
 

Definition at line 19 of file thd_warps.c.

References AFNI_make_voxmap(), THD_linear_mapping::bot, CURRENT_DAXES, THD_3dim_dataset::daxes, EXIT, LOAD_FVEC3, myXtFree, myXtNew, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, THD_warp::rig_bod, THD_warp::tal_12, THD_3dmm_to_3dfind(), THD_dicomm_to_3dmm(), THD_linear_mapping::top, THD_warp::type, THD_affine_warp::warp, THD_talairach_12_warp::warp, WARP_AFFINE_TYPE, and WARP_TALAIRACH_12_TYPE.

Referenced by AFNI_dataset_slice().

00022 {
00023    THD_warp * newwarp ;
00024    THD_linear_mapping * map ;
00025    THD_dataxes * new_daxes ;
00026 
00027    newwarp       = myXtNew( THD_warp ) ;
00028    newwarp->type = inwarp->type ;
00029    new_daxes     = CURRENT_DAXES(new_dset) ;
00030 
00031    switch( inwarp->type ){
00032 
00033       default:{
00034          fprintf(stderr,"\a\n*** ILLEGAL warp code!!! %d\n",inwarp->type) ;
00035          sleep(1) ; EXIT(1) ;
00036       }
00037       break ;
00038 
00039       case WARP_AFFINE_TYPE:{
00040 
00041          map = AFNI_make_voxmap( &(inwarp->rig_bod.warp),
00042                                  old_dset->daxes , new_daxes ) ;
00043 
00044          /* load the (inclusive) voxel index ranges into the affine map */
00045 
00046          LOAD_FVEC3( map->bot, 0,0,0 ) ;
00047          LOAD_FVEC3( map->top, new_daxes->nxx-1,
00048                                new_daxes->nyy-1, new_daxes->nzz-1 ) ;
00049 
00050 
00051          newwarp->rig_bod.warp = *map ;
00052 
00053          myXtFree( map ) ;
00054       }
00055       break ;
00056 
00057       case WARP_TALAIRACH_12_TYPE:{
00058          int iw ;
00059          for( iw=0 ; iw < 12 ; iw++ ){
00060             map = AFNI_make_voxmap( &(inwarp->tal_12.warp[iw]) ,
00061                                     old_dset->daxes , new_daxes ) ;
00062 
00063             map->bot = THD_dicomm_to_3dmm(new_dset,inwarp->tal_12.warp[iw].bot);
00064             map->top = THD_dicomm_to_3dmm(new_dset,inwarp->tal_12.warp[iw].top);
00065 
00066             map->bot = THD_3dmm_to_3dfind( new_dset , map->bot ) ;
00067             map->top = THD_3dmm_to_3dfind( new_dset , map->top ) ;
00068 
00069             newwarp->tal_12.warp[iw] = *map ;
00070 
00071             myXtFree( map ) ;
00072          }
00073       }
00074       break ;
00075    }
00076 
00077    return newwarp ;
00078 }

void AFNI_serverlog char *    str
 

Log the input string to the AFNI server. Sends an HTTP request with the input string as the 'user agent', which will be saved in the Web server logs. --------------------------------------------------------------------------

Definition at line 21 of file thd_logafni.c.

References AFNI_noenv(), AFNI_REQUEST, AFNI_SERVER, malloc, NI_sleep(), NI_stream_closenow(), NI_stream_open(), NI_stream_write(), and NI_stream_writecheck().

00022 {
00023    pid_t child_pid ;
00024    NI_stream ns ;
00025    int nbuf=0 , jj ;
00026    char *sbuf , *rbuf , *ss ;
00027 
00028    if( str == NULL || *str == '\0'      ) return ;
00029    if( AFNI_noenv("AFNI_VERSION_CHECK") ) return ;
00030 
00031    /*-- start the child process --*/
00032 
00033    child_pid = fork() ;
00034    if( child_pid != (pid_t)0 ) return ;   /* parent is done */
00035 
00036    /*-- child will never return alive! --*/
00037 
00038    /* open stream to server */
00039 
00040    ns = NI_stream_open( AFNI_SERVER , "w" ) ;
00041    if( ns == (NI_stream)NULL ) _exit(0) ;
00042 
00043    /* copy input string, replace bad chars with spaces */
00044 
00045    sbuf = strdup(str) ;
00046    for( ss=sbuf ; *ss != '\0' ; ss++ ) if( !isgraph(*ss) ) *ss = ' ' ;
00047 
00048    /* truncate trailing spaces */
00049 
00050    nbuf = strlen(sbuf) ;
00051    for( ss=sbuf+(nbuf-1) ; isspace(*ss) ; ss-- ) *ss = '\0' ;
00052 
00053    /* build request to AFNI server */
00054 
00055    nbuf = strlen(sbuf)+strlen(AFNI_REQUEST)+32 ;
00056    rbuf = (char *)malloc(nbuf) ;
00057    sprintf(rbuf,AFNI_REQUEST,sbuf) ;
00058 
00059    /* wait for stream to get good for writing */
00060 
00061    jj = NI_stream_writecheck( ns , 1234 ) ;
00062    if( jj < 1 ) _exit(0) ;
00063 
00064    /* send the request */
00065 
00066    NI_stream_write( ns , rbuf , strlen(rbuf) ) ;
00067 
00068    /* don't read response: wait a decent interval, close connection, quit */
00069 
00070    NI_sleep(1) ; NI_stream_closenow(ns) ; _exit(0) ;
00071 }

void AFNI_sleep int   
 

Definition at line 26 of file afni_logger.c.

Referenced by AFNI_logger(), and drive_MCW_grapher().

00027 {
00028    struct timeval tv ;
00029    if( msec <= 0 ) return ;
00030    tv.tv_sec  = msec/1000 ;
00031    tv.tv_usec = (msec%1000)*1000 ;
00032    select( 1 , NULL,NULL,NULL , &tv ) ;
00033    return ;
00034 }

void B64_set_crlf int    nn
 

Set the number of characters to use for end of line: 1 = Unix standard (LF only); 2 = DOS standard (CR LF). ------------------------------------------------------------------------

Definition at line 19 of file niml_b64.c.

00020 {
00021    if( nn >= 1 && nn <= 2 ) ncrlf  = nn ;
00022    else                     nocrlf = !nocrlf ;
00023    return ;
00024 }

void B64_set_linelen int    ll
 

Set the length of a line of output in base64; ll should be between 16 and 76 (inclusive). Will round down to a multiple of 4. ------------------------------------------------------------------------

Definition at line 31 of file niml_b64.c.

00032 {
00033    if( ll >= 16 && ll <= 76 ) linelen = 4*(ll/4) ; /* multiple of 4 */
00034    else                       linelen = 72 ;       /* default */
00035    return ;
00036 }

void B64_to_base64 int    nbin,
byte   bin,
int *    nb64,
byte **    b64
 

Convert binary array to base64 encoding.

Inputs: nbin = number of bytes in bin bin = array of binary bytes to encode

Outputs: *nb64 = number of base64 bytes [*nb64==0 flags an error] b64 = pointer to newly malloc()-ed space with bytes

The output array (*b64) line length can be set by B64_set_linelen(n) where n is from 16 to 76. The default is 72. Note, however, that encoded bytes will always be written out in groups of 4. The output array line separator can be the LF character only (Unix) or the CR-LF combination (DOS, etc.). This is controlled by B64_set_crlf(n) where n=1 for LF, n=2 for CR LF. The default is LF. The output array will be terminated with a line separator. If you call B64_set_crlf(0) then this will toggle the use of line separators.

There will be no ASCII NUL character at the end of *b64 -- that is, the output is not a C string.

Example:

  • byte *b64 , *bin ;
  • int nb64=0 , nbin ;
  • **load bin and nbin somehow**
  • B64_to_base64( nbin,bin , &nb64,&b64 ) ;
  • if( nb64 == 0 ){ **failure** }
  • else { **b64[0..nb64-1] is encoded data** printf("%.*s
    ",nb64,b64) ; } ------------------------------------------------------------------------

Definition at line 177 of file niml_b64.c.

00178 {
00179    int ii,jj , nn,n3 ;
00180    byte a,b,c , w,x,y,z ;
00181 
00182    /*- sanity checks -*/
00183 
00184    if( nb64 == NULL || b64 == NULL ) return ;
00185    if( nbin <= 0    || bin == NULL ){ *nb64 = 0 ; *b64 = NULL ; return ; }
00186 
00187    /* calculate size of output (3 bytes in -> 4 bytes out, plus EOL */
00188 
00189    nn   = (int)((4.0*(linelen+ncrlf+1.0)/(3.0*linelen))*nbin + 256.0) ;
00190    *b64 = (byte *) malloc(sizeof(byte)*nn) ;
00191    if( *b64 == NULL ){ *nb64 = 0 ; return ; }  /* this is bad */
00192 
00193    /*- do blocks of 3 bytes in -*/
00194 
00195    load_encode_table() ;
00196    n3 = (nbin/3)*3 ;
00197    for( nn=jj=ii=0 ; ii < n3 ; ){
00198 
00199       /* encode next 3 bytes to 4 outputs */
00200 
00201       a = bin[ii++] ; b = bin[ii++] ; c = bin[ii++] ;
00202       B64_encode3(a,b,c,w,x,y,z) ;
00203       (*b64)[jj++] = w ;
00204       (*b64)[jj++] = x ;
00205       (*b64)[jj++] = y ;
00206       (*b64)[jj++] = z ;
00207 
00208       /* if we past the line length, add the EOL stuff */
00209 
00210       if( !nocrlf ){
00211         nn += 4 ; if( nn >= linelen ){
00212                      if( ncrlf == 2 ) (*b64)[jj++] = B64_EOL1 ;
00213                      (*b64)[jj++] = B64_EOL2 ;
00214                      nn = 0 ;
00215                   }
00216       }
00217    }
00218 
00219    /*- do the leftover data, if any (1 or 2 bytes) -*/
00220 
00221    if( ii < nbin ){
00222       if( ii == nbin-2 )
00223          B64_encode2(bin[ii],bin[ii+1],w,x,y,z) ;
00224       else
00225          B64_encode1(bin[ii],w,x,y,z) ;
00226 
00227       (*b64)[jj++] = w ;
00228       (*b64)[jj++] = x ;
00229       (*b64)[jj++] = y ;
00230       (*b64)[jj++] = z ; nn += 4 ;
00231    }
00232 
00233    /* if any output bytes are left, add EOL */
00234 
00235    if( nn > 0 && !nocrlf ){
00236       if( ncrlf == 2 ) (*b64)[jj++] = B64_EOL1 ;
00237       (*b64)[jj++] = B64_EOL2 ;
00238    }
00239 
00240    /* resize output array to be exact fit */
00241 
00242    *b64  = (byte *) realloc( *b64 , sizeof(byte)*jj ) ;
00243    *nb64 = jj ;
00244    return ;
00245 }

void B64_to_binary int    nb64,
byte   b64,
int *    nbin,
byte **    bin
 

Convert base64-encoded array to a binary array (decoding).

Inputs:

  • nb64 = number of bytes in b64
  • b64 = array of base64 encoding bytes
    • values not in the base64 encoding set will be skipped
Outputs:
  • *nbin = number of binary bytes [*nbin==0 flags an error]
  • *bin = pointer to newly malloc()-ed space with bytes
Example:
  • byte *b64 , *bin ;
  • int nb64 , nbin=0 ;
  • **load b64 and nb64 somehow**
  • B64_to_binary( nb64,b64 , &nbin, &bin ) ;
  • if( nbin == 0 ){ **failure** }
  • else { **bin[0..nbin-1] is decoded data** } ------------------------------------------------------------------------

Definition at line 92 of file niml_b64.c.

00093 {
00094    int ii,jj , nn ;
00095    byte a,b,c , w,x,y,z ;
00096 
00097    /*- sanity checks -*/
00098 
00099    if( nbin == NULL || bin == NULL ) return ;
00100 
00101    if( nb64 < 4 || b64 == NULL ){ *nbin = 0 ; *bin = NULL ; return ; }
00102 
00103    *bin = (byte *) malloc(sizeof(byte)*(2+3*nb64/4)) ;
00104    if( *bin == NULL ){ *nbin = 0 ; return ; }
00105 
00106    /*- some work -*/
00107 
00108    load_decode_table() ;
00109    for( ii=jj=0 ; ii < nb64 ; ){  /* scan inputs, skipping bad characters */
00110 
00111       /* get next 4 characters (use '=' if we hit the end early) */
00112 
00113       w = b64[ii++] ;
00114       while( !B64_goodchar(w) && ii < nb64 ) w = b64[ii++] ;
00115       x = (ii < nb64) ? b64[ii++] : '=' ;
00116       while( !B64_goodchar(x) && ii < nb64 ) x = b64[ii++] ;
00117       y = (ii < nb64) ? b64[ii++] : '=' ;
00118       while( !B64_goodchar(y) && ii < nb64 ) y = b64[ii++] ;
00119       z = (ii < nb64) ? b64[ii++] : '=' ;
00120       while( !B64_goodchar(z) && ii < nb64 ) z = b64[ii++] ;
00121 
00122       B64_decode4(w,x,y,z,a,b,c) ;           /* decode 4 bytes into 3 */
00123 
00124       if( z == '=' ){                        /* got to the end? */
00125          nn = B64_decode_count(w,x,y,z) ;    /* see how many to save */
00126          if( nn > 0 ) (*bin)[jj++] = a ;
00127          if( nn > 1 ) (*bin)[jj++] = b ;
00128          break ;                             /* end of decoding loop */
00129       }
00130 
00131       /* not at the end => save all 3 outputs, loop back */
00132 
00133       (*bin)[jj++] = a ; (*bin)[jj++] = b ; (*bin)[jj++] = c ;
00134    }
00135 
00136    /* resize output array to be exact fit */
00137 
00138    *bin  = (byte *) realloc( *bin , sizeof(byte)*jj ) ;
00139    *nbin = jj ;
00140    return ;
00141 }

void brainnormalize_coord float    ispat,
float    jspat,
float    kspat,
float *    iorig,
float *    jorig,
float *    korig,
THD_3dim_dataset   origset,
float *    xrai_orig,
float *    yrai_orig,
float *    zrai_orig
 

takes in voxel indices into the Spat Normed volume (RAI) and returns voxel indices and coordinates in the original volume. Used to figure out shift to apply to surface model to align it with original volume.

Parameters:
ispat  (float) 3D i index into spat norm volume
jspat  (float) 3D j index into spat norm volume
kspat  (float) 3D k index into spat norm volume
iorig  (float*) 3D i index into original volume
jorig  (float*) 3D j index into original volume
korig  (float*) 3D k index into original volume
origset  (THD_3dim_dataset *) Le original dataset
xrai_orig  (float *) X coordinate in original volume (dicomm)
yrai_orig  (float *) Y coordinate in original volume (dicomm)
zrai_orig  (float *) Z coordinate in original volume (dicomm)
ZSS Sometime in April 05

See also:
brainnormalize_inv_coord

Definition at line 1023 of file thd_brainormalize.c.

References CURRENT_DAXES, THD_3dim_dataset::daxes, ijkwarp(), THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, THD_3dmm_to_dicomm(), THD_BN_XORG, THD_BN_YORG, THD_BN_ZORG, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::yyorient, THD_dataxes::zzdel, THD_dataxes::zzorg, and THD_dataxes::zzorient.

01027 {
01028    THD_dataxes * daxes ;
01029    THD_fvec3     fv, fvdic ;
01030    float irai, jrai, krai;
01031    
01032    /* find out corresponding indices in original dset */
01033    ijkwarp(ispat, jspat, kspat , &irai, &jrai, &krai);
01034    
01035 
01036     
01037    /* These indices assume an RAI dset orientation */
01038       /* Find out what these indices should be in origset's orientation */
01039       switch( origset->daxes->xxorient ){
01040         case ORI_R2L_TYPE: *iorig =  irai ; break ;
01041         case ORI_L2R_TYPE: *iorig =  origset->daxes->nxx - irai ; break ;
01042         case ORI_P2A_TYPE: *iorig =  origset->daxes->nxx - jrai  ; break ;
01043         case ORI_A2P_TYPE: *iorig =  jrai ; break ;
01044         case ORI_I2S_TYPE: *iorig =  krai ; break ;
01045         case ORI_S2I_TYPE: *iorig =  origset->daxes->nxx - krai ; break ;
01046       }
01047       switch( origset->daxes->yyorient ){
01048         case ORI_R2L_TYPE: *jorig =  irai ; break ;
01049         case ORI_L2R_TYPE: *jorig =  origset->daxes->nyy - irai  ; break ;
01050         case ORI_P2A_TYPE: *jorig =  origset->daxes->nyy - jrai ; break ;
01051         case ORI_A2P_TYPE: *jorig =  jrai ; break ;
01052         case ORI_I2S_TYPE: *jorig =  krai ; break ;
01053         case ORI_S2I_TYPE: *jorig =  origset->daxes->nyy - krai ; break ;
01054       }
01055       switch( origset->daxes->zzorient ){
01056         case ORI_R2L_TYPE: *korig =  irai ; break ;
01057         case ORI_L2R_TYPE: *korig =  origset->daxes->nzz - irai ; break ;
01058         case ORI_P2A_TYPE: *korig =  origset->daxes->nzz - jrai ; break ;
01059         case ORI_A2P_TYPE: *korig =  jrai ; break ;
01060         case ORI_I2S_TYPE: *korig =  krai ; break ;
01061         case ORI_S2I_TYPE: *korig =  origset->daxes->nzz - krai ; break ;
01062       }
01063       
01064             
01065       /* change indices into mm coords in orig dset*/
01066       daxes = CURRENT_DAXES(origset) ;
01067 
01068       fv.xyz[0] = daxes->xxorg + *iorig * daxes->xxdel ;  /* 3dfind_to_3dmm */
01069       fv.xyz[1] = daxes->yyorg + *jorig * daxes->yydel ;
01070       fv.xyz[2] = daxes->zzorg + *korig * daxes->zzdel ;
01071 
01072       fvdic = THD_3dmm_to_dicomm(origset,   fv );                /* 3dmm_to_dicomm  */
01073       *xrai_orig = fvdic.xyz[0];
01074       *yrai_orig = fvdic.xyz[1]; 
01075       *zrai_orig = fvdic.xyz[2];
01076        
01077    /* report for sanity */
01078    if (0) {
01079       fprintf(stderr,   "brainnormalize_coord:\n"
01080                      " ijk_spat_rai = [%f %f %f]\n"
01081                      " ijk_orig_rai = [%f %f %f] (in rai order, not native to iset!)\n"
01082                      " ijk_orig     = [%f %f %f] (in native order)\n"
01083                      " XYZ_orig     = [%f %f %f]\n"
01084                      " Origin spat = [%f %f %f]\n", 
01085                      ispat, jspat, kspat,
01086                      irai, jrai, krai ,
01087                      *iorig, *jorig, *korig ,
01088                      *xrai_orig, *yrai_orig, *zrai_orig,
01089                      THD_BN_XORG, THD_BN_YORG, THD_BN_ZORG);   
01090    }      
01091    return;
01092 } 

int breakup_string char *    sin,
char ***    stok
 

Definition at line 81 of file thd_strfunc.c.

References DQUOT, malloc, NUL, realloc, and SQUOT.

Referenced by AFNI_drive_addto_graph_1D(), AFNI_drive_addto_graph_xy(), AFNI_drive_clear_graph_1D(), AFNI_drive_clear_graph_xy(), AFNI_drive_close_graph_xy(), AFNI_drive_geom_graph(), AFNI_drive_open_graph_1D(), AFNI_drive_open_graph_xy(), and TTRR_load_file().

00082 {
00083    int n_tok , quote , ll ;
00084    char **s_tok , *cpt , *sss , qch=NUL ;
00085 
00086    if( stok == NULL || sin == NULL || sin[0] == NUL ) return -1 ;
00087 
00088    n_tok = 0 ;
00089    s_tok = NULL ;
00090 
00091    cpt = sin ;
00092 
00093    while( *cpt != '\0' ){  /* loop until we use up the input string */
00094 
00095       /* skip whitespace */
00096 
00097       while( isspace(*cpt) ) cpt++ ;
00098       if( *cpt == NUL ) break ;        /* reached end */
00099 
00100       /* if starts with a quote, note that factoid */
00101 
00102       if( *cpt == SQUOT || *cpt == DQUOT ){
00103          quote = 1 ; qch = *cpt ; cpt++ ;   /* qch = quote character */
00104          if( *cpt == NUL ) break ;
00105       } else {
00106         quote = 0 ;
00107       }
00108 
00109       /* scan until end of sub-string (next quote, or next nonblank) */
00110 
00111       sss = cpt ;    /* start of sub-string */
00112       if( quote ){
00113          while( *cpt != NUL && *cpt != qch    ) cpt++ ;  /* scan to next quote */
00114       } else {
00115          while( *cpt != NUL && !isspace(*cpt) ) cpt++ ;  /* to next non-blank */
00116       }
00117 
00118       /* cpt now points to character after end of sub-string */
00119 
00120       ll = cpt - sss ;  /* number of characters in sub-string (may be zero) */
00121 
00122       /* make a new entry in the string table */
00123 
00124       s_tok = (char **) realloc( s_tok , sizeof(char *) * (n_tok+1) ) ;
00125       s_tok[n_tok] = (char *) malloc(ll+4) ;
00126       if( ll > 0 ) memcpy( s_tok[n_tok] , sss , ll ) ;
00127       s_tok[n_tok][ll] = NUL ;
00128       n_tok++ ;
00129 
00130       /* skip the character after the end of sub-string */
00131 
00132       if( *cpt == NUL ) break ;  /* end of the line, baby [14 Apr 2005] */
00133       cpt++ ;
00134    } /* end of loop over input string */
00135 
00136    *stok = s_tok ; return n_tok ;
00137 }

Tmask* create_Tmask_byte int   ,
int   ,
int   ,
byte  
 

Definition at line 23 of file thd_tmask.c.

References calloc, malloc, Tmask::mask, Tmask::nmask, nz, TM_IXY, TM_IYZ, and TM_IZX.

Referenced by CREN_render().

00024 {
00025    Tmask * tm ;
00026    int ii,jj,kk,vv , nxy,nyz,nzx ;
00027    byte * bz , *xym,*yzm,*zxm , *bxy,*byz,*bzx ;
00028 
00029    tm = (Tmask *) malloc(sizeof(Tmask)) ;
00030    tm->nmask[TM_IXY] = nxy = nx*ny ;
00031    tm->nmask[TM_IYZ] = nyz = ny*nz ;
00032    tm->nmask[TM_IZX] = nzx = nz*nx ;
00033 
00034    tm->mask[TM_IXY] = xym = (byte *) calloc(1,sizeof(byte)*nxy) ;
00035    tm->mask[TM_IYZ] = yzm = (byte *) calloc(1,sizeof(byte)*nyz) ;
00036    tm->mask[TM_IZX] = zxm = (byte *) calloc(1,sizeof(byte)*nzx) ;
00037 
00038    for( byz=yzm,kk=0 ; kk < nz ; kk++,byz+=ny ){
00039       bz = vol + kk*nxy ;
00040       for( bxy=xym,jj=0 ; jj < ny ; jj++,bz+=nx,bxy+=nx ){
00041          for( bzx=zxm,ii=0 ; ii < nx ; ii++,bzx+=nz ){
00042             if( bz[ii] ){ bxy[ii] = byz[jj] = bzx[kk] = 1 ; }
00043          }
00044       }
00045    }
00046 
00047    return tm ;
00048 }

Tmask* create_Tmask_rgba int   ,
int   ,
int   ,
rgba  
 

Definition at line 52 of file thd_tmask.c.

References rgba::a, calloc, malloc, Tmask::mask, Tmask::nmask, nz, TM_IXY, TM_IYZ, and TM_IZX.

00053 {
00054    Tmask *tm ;
00055    int ii,jj,kk,vv , nxy,nyz,nzx ;
00056    byte *xym,*yzm,*zxm , *bxy,*byz,*bzx ;
00057    rgba *bz ;
00058 
00059    tm = (Tmask *) malloc(sizeof(Tmask)) ;
00060    tm->nmask[TM_IXY] = nxy = nx*ny ;
00061    tm->nmask[TM_IYZ] = nyz = ny*nz ;
00062    tm->nmask[TM_IZX] = nzx = nz*nx ;
00063 
00064    tm->mask[TM_IXY] = xym = (byte *) calloc(1,sizeof(byte)*nxy) ;
00065    tm->mask[TM_IYZ] = yzm = (byte *) calloc(1,sizeof(byte)*nyz) ;
00066    tm->mask[TM_IZX] = zxm = (byte *) calloc(1,sizeof(byte)*nzx) ;
00067 
00068    for( byz=yzm,kk=0 ; kk < nz ; kk++,byz+=ny ){
00069      bz = vol + kk*nxy ;
00070      for( bxy=xym,jj=0 ; jj < ny ; jj++,bz+=nx,bxy+=nx ){
00071        for( bzx=zxm,ii=0 ; ii < nx ; ii++,bzx+=nz ){
00072          if( bz[ii].a ){ bxy[ii] = byz[jj] = bzx[kk] = 1 ; }
00073        }
00074      }
00075    }
00076 
00077    return tm ;
00078 }

void cub_shift int   ,
float   ,
float *   
 

Definition at line 391 of file thd_shift2.c.

References ENTRY, FINS, free, lcbuf, malloc, nlcbuf, P_00, P_M1, P_P1, and P_P2.

Referenced by cub_shift2().

00392 {
00393    int   ii , ia , ix ;
00394    float  wt_m1 , wt_00 , wt_p1 , wt_p2 , aa ;
00395 #ifdef SEPARATE_FINS
00396    int ibot,itop ;
00397 #endif
00398 
00399 ENTRY("cub_shift") ;
00400 
00401    af = -af ; ia = (int) af ; if( af < 0 ) ia-- ;  /* ia = floor */
00402 
00403    /* 15 Mar 2001: if shift is too large, return all zeros */
00404 
00405    if( ia <= -n || ia >= n ){
00406       for( ii=0 ; ii < n ; ii++ ) f[ii] = 0.0 ;
00407       EXRETURN ;
00408    }
00409 
00410    aa = af - ia ;
00411    wt_m1 = P_M1(aa) ; wt_00 = P_00(aa) ;
00412    wt_p1 = P_P1(aa) ; wt_p2 = P_P2(aa) ;
00413 
00414    if( n > nlcbuf ){
00415       if( lcbuf != NULL ) free(lcbuf) ;
00416       lcbuf  = (float *) malloc( sizeof(float) * n ) ;
00417       nlcbuf = n ;
00418    }
00419 
00420 #ifdef SEPARATE_FINS
00421    ibot = 1-ia ;   if( ibot < 0   ) ibot = 0 ;
00422    itop = n-3-ia ; if( itop > n-1 ) itop = n-1 ;
00423 
00424    for( ii=ibot ; ii <= itop ; ii++ ){
00425       ix = ii + ia ;
00426       lcbuf[ii] =  wt_m1 * f[ix-1] + wt_00 * f[ix]
00427                  + wt_p1 * f[ix+1] + wt_p2 * f[ix+2] ;
00428    }
00429 
00430    if( ibot > n ) ibot = n ; /* 15 Mar 2001 */
00431    for( ii=0 ; ii < ibot ; ii++ ){
00432       ix = ii + ia ;
00433       lcbuf[ii] =  wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00434                  + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) ;
00435    }
00436 
00437    if( itop < 0 ) itop = -1 ; /* 15 Mar 2001 */
00438    for( ii=itop+1 ; ii < n ; ii++ ){
00439       ix = ii + ia ;
00440       lcbuf[ii] =  wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00441                  + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) ;
00442    }
00443 #else /* not SEPARATE_FINS */
00444    for( ii=0 ; ii < n ; ii++ ){
00445       ix = ii + ia ;
00446       if( ix > 0 && ix < n-2 )
00447          lcbuf[ii] =  wt_m1 * f[ix-1] + wt_00 * f[ix]
00448                     + wt_p1 * f[ix+1] + wt_p2 * f[ix+2] ;
00449       else
00450          lcbuf[ii] =  wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00451                     + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) ;
00452    }
00453 #endif /* SEPARATE_FINS */
00454 
00455    memcpy( f , lcbuf , sizeof(float)*n ) ;
00456    EXRETURN ;
00457 }

void cub_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 459 of file thd_shift2.c.

References cub_shift().

Referenced by SHIFT_set_method().

00460 {
00461                    cub_shift( n , af , f ) ;
00462    if( g != NULL ) cub_shift( n , ag , g ) ;
00463    return ;
00464 }

THD_dvecmat DLSQ_affine int    n,
THD_dfvec3   xx,
THD_dfvec3   yy
 

Compute an affine transformation to take one set of vectors into another. That is, find general matrix R and vector B so that

yy = [R] xx + V (k=0..n-1) k k

is true in the unweighted least squares sense. ----------------------------------------------------------------------------

Definition at line 989 of file thd_shear3d.c.

References ADD_DFVEC3, DMAT_INV, DMAT_MUL, DMATVEC, LOAD_DFVEC3, LOAD_DIAG_DMAT, LOAD_ZERO_DMAT, THD_dmat33::mat, THD_dvecmat::mm, SUB_DFVEC3, THD_dvecmat::vv, and THD_dfvec3::xyz.

Referenced by main().

00990 {
00991    THD_dvecmat out ;
00992    THD_dfvec3  cx,cy , tx,ty ;
00993    THD_dmat33  yxt , xtx , xtxinv ;
00994    int ii,jj,kk ;
00995    double wsum ;
00996 
00997    /*- check for bad inputs -*/
00998 
00999    if( n < 3 || xx == NULL || yy == NULL ){ LOAD_ZERO_DMAT(out.mm); return out; }
01000 
01001    /*- compute centroids of each set of vectors -*/
01002 
01003    LOAD_DFVEC3(cx,0,0,0) ; LOAD_DFVEC3(cy,0,0,0) ; wsum = 0.0 ;
01004    for( kk=0 ; kk < n ; kk++ ){
01005      cx = ADD_DFVEC3(cx,xx[kk]) ;  /* sums of vectors */
01006      cy = ADD_DFVEC3(cy,yy[kk]) ;
01007    }
01008    wsum = 1.0 / n ;
01009    cx.xyz[0] *= wsum ; cx.xyz[1] *= wsum ; cx.xyz[2] *= wsum ;  /* centroids */
01010    cy.xyz[0] *= wsum ; cy.xyz[1] *= wsum ; cy.xyz[2] *= wsum ;
01011 
01012    /*- compute products of data matrices -*/
01013 
01014    LOAD_DIAG_DMAT(yxt,1.e-9,1.e-9,1.e-9) ;
01015    LOAD_DIAG_DMAT(xtx,1.e-9,1.e-9,1.e-9) ;
01016    for( kk=0 ; kk < n ; kk++ ){
01017      tx = SUB_DFVEC3( xx[kk] , cx ) ;  /* remove centroids */
01018      ty = SUB_DFVEC3( yy[kk] , cy ) ;
01019      for( jj=0 ; jj < 3 ; jj++ ){
01020        for( ii=0 ; ii < 3 ; ii++ ){
01021          yxt.mat[ii][jj] += ty.xyz[ii]*tx.xyz[jj] ;
01022          xtx.mat[ii][jj] += tx.xyz[ii]*tx.xyz[jj] ;
01023        }
01024      }
01025    }
01026    xtxinv = DMAT_INV( xtx ) ;
01027    out.mm = DMAT_MUL( yxt , xtxinv ) ;
01028    tx = DMATVEC( out.mm , cx ) ;
01029    out.vv = SUB_DFVEC3( cy , tx ) ;
01030    return out ;
01031 }

THD_dvecmat DLSQ_rot_trans int   ,
THD_dfvec3  ,
THD_dfvec3  ,
double *   
 

Definition at line 906 of file thd_shear3d.c.

00907 {
00908    THD_dvecmat out ;
00909    THD_dfvec3  cx,cy , tx,ty ;
00910    THD_dmat33  cov ;
00911    double *wt , wsum , dd ;
00912    int ii,jj,kk ;
00913 
00914    /*- check for bad inputs -*/
00915 
00916    if( n < 3 || xx == NULL || yy == NULL ){ LOAD_ZERO_DMAT(out.mm); return out; }
00917 
00918    /*- make a fake weight array, if none supplied -*/
00919 
00920    if( ww == NULL ){
00921       wt = (double *) malloc(sizeof(double)*n) ;
00922       for( kk=0 ; kk < n ; kk++ ) wt[kk] = 1.0 ;
00923    } else {
00924       wt = ww ;
00925    }
00926 
00927    /*- compute centroids of each set of vectors -*/
00928 
00929    LOAD_DFVEC3(cx,0,0,0) ; LOAD_DFVEC3(cy,0,0,0) ; wsum = 0.0 ;
00930    for( kk=0 ; kk < n ; kk++ ){
00931       cx = SCLADD_DFVEC3(1,cx,wt[kk],xx[kk]) ;  /* weighted sums of vectors */
00932       cy = SCLADD_DFVEC3(1,cy,wt[kk],yy[kk]) ;
00933       wsum += wt[kk] ;                          /* sum of weights */
00934    }
00935    wsum = 1.0 / wsum ;
00936    cx.xyz[0] *= wsum ; cx.xyz[1] *= wsum ; cx.xyz[2] *= wsum ;  /* centroids */
00937    cy.xyz[0] *= wsum ; cy.xyz[1] *= wsum ; cy.xyz[2] *= wsum ;
00938 
00939    /*- compute covariance matrix -*/
00940 
00941    LOAD_DIAG_DMAT(cov,1.e-10,1.e-10,1.e-10) ;
00942    for( kk=0 ; kk < n ; kk++ ){
00943       tx = SUB_DFVEC3( xx[kk] , cx ) ;  /* remove centroids */
00944       ty = SUB_DFVEC3( yy[kk] , cy ) ;
00945       for( jj=0 ; jj < 3 ; jj++ )
00946          for( ii=0 ; ii < 3 ; ii++ )
00947             cov.mat[ii][jj] += wt[kk]*tx.xyz[ii]*ty.xyz[jj] ;
00948    }
00949    dd = ( fabs(cov.mat[0][0]) + fabs(cov.mat[1][1]) + fabs(cov.mat[2][2]) ) / 3.0 ;
00950 #if 0
00951 fprintf(stderr,"dd=%g  diag=%g %g %g\n",dd,cov.mat[0][0],cov.mat[1][1],cov.mat[2][2] ) ;
00952 #endif
00953    dd = dd / 1.e9 ;
00954 #if 0
00955 fprintf(stderr,"dd=%g\n",dd) ;
00956 #endif
00957    if( cov.mat[0][0] < dd ) cov.mat[0][0] = dd ;
00958    if( cov.mat[1][1] < dd ) cov.mat[1][1] = dd ;
00959    if( cov.mat[2][2] < dd ) cov.mat[2][2] = dd ;
00960 
00961 #if 0
00962 DUMP_DMAT33( "cov" , cov ) ;
00963 #endif
00964 
00965    out.mm = DMAT_svdrot_newer( cov ) ;  /* compute rotation matrix [R] */
00966 
00967 #if 0
00968 DUMP_DMAT33( "out.mm" , out.mm ) ;
00969 #endif
00970 
00971    tx = DMATVEC( out.mm , cx ) ;     /* compute translation vector V */
00972    out.vv = SUB_DFVEC3( cy , tx ) ;
00973 
00974    if( wt != ww ) free(wt) ;               /* toss the trash, if any */
00975 
00976    return out ;
00977 }

THD_dvecmat DLSQ_rotscl int    n,
THD_dfvec3   xx,
THD_dfvec3   yy,
int    ndim
 

Compute a transformation to take one set of vectors into another. That is, find matrix R and vector B so that

yy = [R] xx + V (k=0..n-1) k k

is true in the unweighted least squares sense. Here, we restrict R to be a scalar multiple of an orthgonal matrix. ----------------------------------------------------------------------------

Definition at line 1044 of file thd_shear3d.c.

References ADD_DFVEC3, DMAT_DET, DMAT_INV, DMAT_MUL, DMAT_pow(), DMAT_SCALAR, DMATVEC, LOAD_DFVEC3, LOAD_DIAG_DMAT, LOAD_ZERO_DMAT, THD_dmat33::mat, THD_dvecmat::mm, SUB_DFVEC3, THD_dvecmat::vv, and THD_dfvec3::xyz.

Referenced by main().

01045 {
01046    THD_dvecmat out ;
01047    THD_dfvec3  cx,cy , tx,ty ;
01048    THD_dmat33  yxt , xtx , xtxinv , aa,bb,cc ;
01049    int ii,jj,kk ;
01050    double wsum ;
01051 
01052    /*- check for bad inputs -*/
01053 
01054    if( n < 3 || xx == NULL || yy == NULL ){ LOAD_ZERO_DMAT(out.mm); return out; }
01055 
01056    /*- compute centroids of each set of vectors -*/
01057 
01058    LOAD_DFVEC3(cx,0,0,0) ; LOAD_DFVEC3(cy,0,0,0) ; wsum = 0.0 ;
01059    for( kk=0 ; kk < n ; kk++ ){
01060      cx = ADD_DFVEC3(cx,xx[kk]) ;  /* sums of vectors */
01061      cy = ADD_DFVEC3(cy,yy[kk]) ;
01062    }
01063    wsum = 1.0 / n ;
01064    cx.xyz[0] *= wsum ; cx.xyz[1] *= wsum ; cx.xyz[2] *= wsum ;  /* centroids */
01065    cy.xyz[0] *= wsum ; cy.xyz[1] *= wsum ; cy.xyz[2] *= wsum ;
01066 
01067    /*- compute products of data matrices -*/
01068 
01069    LOAD_DIAG_DMAT(yxt,1.e-9,1.e-9,1.e-9) ;
01070    LOAD_DIAG_DMAT(xtx,1.e-9,1.e-9,1.e-9) ;
01071    for( kk=0 ; kk < n ; kk++ ){
01072      tx = SUB_DFVEC3( xx[kk] , cx ) ;  /* remove centroids */
01073      ty = SUB_DFVEC3( yy[kk] , cy ) ;
01074      for( jj=0 ; jj < 3 ; jj++ ){
01075        for( ii=0 ; ii < 3 ; ii++ ){
01076          yxt.mat[ii][jj] += ty.xyz[ii]*tx.xyz[jj] ;
01077          xtx.mat[ii][jj] += tx.xyz[ii]*tx.xyz[jj] ;
01078        }
01079      }
01080    }
01081    xtxinv = DMAT_INV( xtx ) ;
01082    aa = DMAT_MUL( yxt , xtxinv ) ;
01083    bb = DMAT_pow( aa , -0.5 ) ;
01084    cc = DMAT_MUL( aa , bb) ;
01085    wsum = DMAT_DET(aa); wsum = fabs(wsum);
01086    switch( ndim ){
01087      default:
01088      case 3: wsum = pow(wsum,0.333333333333) ; break ;  /* 3D rotation */
01089      case 2: wsum = sqrt(wsum)               ; break ;  /* 2D rotation */
01090    }
01091    out.mm = DMAT_SCALAR( cc , wsum ) ;
01092 
01093    tx = DMATVEC( out.mm , cx ) ;
01094    out.vv = SUB_DFVEC3( cy , tx ) ;
01095    return out ;
01096 }

void ENTROPY_accumulate int   ,
void *   
 

Definition at line 30 of file thd_entropy16.c.

References ENTROPY_setup(), scount, snum, and var.

Referenced by ENTROPY_datablock(), and main().

00031 {
00032    int nn = nbytes/2 , ii ;
00033    unsigned short * sar = (unsigned short *) var ;
00034 
00035    if( scount == NULL ) ENTROPY_setup() ;
00036 
00037    for( ii=0 ; ii < nn ; ii++ ) scount[sar[ii]]++ ;
00038    snum += nn ;
00039 }

double ENTROPY_compute void   
 

Definition at line 45 of file thd_entropy16.c.

References scount, snum, and SNUM.

Referenced by ENTROPY_datablock(), and main().

00046 {
00047    register int ii ;
00048    register double sum ;
00049 
00050    if( scount == NULL || snum == 0 ) return 0.0 ;
00051 
00052    sum = 0.0 ;
00053    for( ii=0 ; ii < SNUM ; ii++ )
00054       if( scount[ii] > 0 ) sum += scount[ii] * log((double)scount[ii]) ;
00055 
00056    sum = -(sum - snum*log((double)snum)) / ( log(2.0) * snum ) ;
00057    return sum ;
00058 }

double ENTROPY_datablock THD_datablock  
 

Definition at line 72 of file thd_entropy16.c.

References DBLK_ARRAY, DBLK_BRICK_BYTES, ENTROPY_accumulate(), ENTROPY_compute(), ENTROPY_setdown(), ENTROPY_setup(), ENTRY, THD_datablock::nvals, and RETURN.

Referenced by ENTROPY_dataset(), and THD_write_datablock().

00073 {
00074    int iv ;
00075    double sum ;
00076 
00077 ENTRY("ENTROPY_datablock") ;
00078 
00079    ENTROPY_setup() ;
00080 
00081    for( iv=0 ; iv < blk->nvals ; iv++ )
00082       ENTROPY_accumulate( DBLK_BRICK_BYTES(blk,iv) , DBLK_ARRAY(blk,iv) ) ;
00083 
00084    sum = ENTROPY_compute() ;
00085    ENTROPY_setdown() ;
00086    RETURN(sum) ;
00087 }

double ENTROPY_dataset THD_3dim_dataset  
 

Definition at line 62 of file thd_entropy16.c.

References THD_3dim_dataset::dblk, DSET_load, DSET_LOADED, ENTROPY_datablock(), and ISVALID_DSET.

Referenced by main().

00063 {
00064    if( !ISVALID_DSET(dset) ) return(0.0) ;
00065    DSET_load(dset) ;
00066    if( !DSET_LOADED(dset) ) return(0.0) ;
00067    return ENTROPY_datablock( dset->dblk ) ;
00068 }

void ENTROPY_setdown void   
 

Definition at line 23 of file thd_entropy16.c.

References free, scount, and snum.

Referenced by ENTROPY_datablock(), and main().

00024 {
00025    if( scount != NULL ){ free(scount); scount = NULL; snum = 0; }
00026 }

void ENTROPY_setup void   
 

Definition at line 14 of file thd_entropy16.c.

References malloc, scount, SNUM, and snum.

Referenced by ENTROPY_accumulate(), ENTROPY_datablock(), and main().

00015 {
00016    if( scount == NULL ) scount = (int *) malloc(sizeof(int)*SNUM) ;
00017    memset( scount , 0 , sizeof(int)*SNUM ) ;
00018    snum = 0 ;
00019 }

MRI_IMAGE* FD_brick_to_mri int   ,
int   ,
FD_brick   br
 

Definition at line 17 of file thd_fdto2D.c.

References base, FD_brick::d1, FD_brick::d2, FD_brick::d3, THD_3dim_dataset::dblk, FD_brick::del1, FD_brick::del2, FD_brick::del3, FD_brick::dset, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, FD_brick::e1, FD_brick::e2, MRI_BYTE_PTR, MRI_COMPLEX_PTR, MRI_DOUBLE_PTR, MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, mri_new(), MRI_RGB_PTR, mri_scale_to_float(), MRI_SHORT_PTR, FD_brick::n1, FD_brick::n2, THD_datablock::nvals, FD_brick::start, STATUS, THD_load_datablock(), and typ.

Referenced by main(), and T3D_getim().

00018 {
00019    MRI_IMAGE * im ;  /* output */
00020    register int ii,di,ei , jj,dj,ej , base , pp ;
00021    char * iar ;      /* brick in the input */
00022    MRI_TYPE typ ;
00023 
00024    /** desire a fake image **/
00025 
00026    if( ival < 0 ){
00027       im     = mri_new( br->n1 , br->n2 , MRI_short ) ;
00028       im->dx = br->del1 ;
00029       im->dy = br->del2 ;
00030       im->dz = br->del3 ;
00031       return im ;
00032    }
00033 
00034    /** otherwise, get ready for a real image **/
00035 
00036    if( ival >= br->dset->dblk->nvals ) return NULL ;
00037 
00038    iar = DSET_ARRAY(br->dset,ival) ;
00039 
00040    if( iar == NULL ){  /* if data needs to be loaded from disk */
00041       (void) THD_load_datablock( br->dset->dblk ) ;
00042       iar = DSET_ARRAY(br->dset,ival) ;
00043       if( iar == NULL ) return NULL ;
00044    }
00045 
00046    typ    = DSET_BRICK_TYPE(br->dset,ival) ;
00047    im     = mri_new( br->n1 , br->n2 , typ ) ;
00048    im->dx = br->del1 ;
00049    im->dy = br->del2 ;
00050    im->dz = br->del3 ;
00051 
00052    switch( typ ){
00053 
00054       default:             /* don't know what to do --> return nada */
00055          mri_free( im ) ;
00056          return NULL ;
00057 
00058       case MRI_byte:{
00059          register byte * ar  = MRI_BYTE_PTR(im) ;
00060          register byte * bar = (byte *) iar ;
00061 
00062          di = br->d1 ; dj = br->d2 ;  /* strides */
00063          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00064          base = br->start + kslice * br->d3 ;
00065 
00066          pp = 0 ;
00067          for( jj=0 ; jj != ej ; jj += dj )
00068             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00069       }
00070       break ;
00071 
00072       case MRI_short:{
00073          register short * ar  = MRI_SHORT_PTR(im) ;
00074          register short * bar = (short *) iar ;
00075 
00076          di = br->d1 ; dj = br->d2 ;  /* strides */
00077          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00078          base = br->start + kslice * br->d3 ;
00079 
00080          pp = 0 ;
00081          for( jj=0 ; jj != ej ; jj += dj )
00082             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00083       }
00084       break ;
00085 
00086       case MRI_float:{
00087          register float * ar  = MRI_FLOAT_PTR(im) ;
00088          register float * bar = (float *) iar ;
00089 
00090          di = br->d1 ; dj = br->d2 ;  /* strides */
00091          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00092          base = br->start + kslice * br->d3 ;
00093 
00094          pp = 0 ;
00095          for( jj=0 ; jj != ej ; jj += dj )
00096             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00097       }
00098       break ;
00099 
00100       case MRI_int:{
00101          register int * ar  = MRI_INT_PTR(im) ;
00102          register int * bar = (int *) iar ;
00103 
00104          di = br->d1 ; dj = br->d2 ;  /* strides */
00105          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00106          base = br->start + kslice * br->d3 ;
00107 
00108          pp = 0 ;
00109          for( jj=0 ; jj != ej ; jj += dj )
00110             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00111       }
00112       break ;
00113 
00114       case MRI_double:{
00115          register double * ar  = MRI_DOUBLE_PTR(im) ;
00116          register double * bar = (double *) iar ;
00117 
00118          di = br->d1 ; dj = br->d2 ;  /* strides */
00119          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00120          base = br->start + kslice * br->d3 ;
00121 
00122          pp = 0 ;
00123          for( jj=0 ; jj != ej ; jj += dj )
00124             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00125       }
00126       break ;
00127 
00128       case MRI_complex:{
00129          register complex * ar  = MRI_COMPLEX_PTR(im) ;
00130          register complex * bar = (complex *) iar ;
00131 
00132          di = br->d1 ; dj = br->d2 ;  /* strides */
00133          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00134          base = br->start + kslice * br->d3 ;
00135 
00136          pp = 0 ;
00137          for( jj=0 ; jj != ej ; jj += dj )
00138             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00139       }
00140       break ;
00141 
00142       case MRI_rgb:{                                           /* 15 Apr 2002 */
00143          register rgbyte * ar  = (rgbyte *) MRI_RGB_PTR(im) ;
00144          register rgbyte * bar = (rgbyte *) iar ;
00145 
00146          di = br->d1 ; dj = br->d2 ;  /* strides */
00147          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00148          base = br->start + kslice * br->d3 ;
00149 
00150          pp = 0 ;
00151          for( jj=0 ; jj != ej ; jj += dj )
00152             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00153       }
00154       break ;
00155 
00156    }
00157 
00158    if( DSET_BRICK_FACTOR(br->dset,ival) != 0.0 ){
00159       MRI_IMAGE * qim ;
00160 STATUS(" scaling to float");
00161       qim = mri_scale_to_float( DSET_BRICK_FACTOR(br->dset,ival) , im ) ;
00162       mri_free(im) ; im = qim ;
00163    }
00164 
00165    return im ;
00166 }

MRI_IMAGE* FD_brick_to_series int   ,
FD_brick   br
 

Definition at line 19 of file thd_fdto1D.c.

References THD_datablock::brick_fac, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, FD_brick::dset, DSET_ARRAY, DSET_BRICK_TYPE, DSET_datum_constant, MRI_IMAGE::dx, THD_ivec3::ijk, ind, LOAD_IVEC3, MRI_BYTE_PTR, MRI_COMPLEX_PTR, MRI_DOUBLE_PTR, MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, mri_mult_to_float(), mri_new(), MRI_RGB_PTR, MRI_RGBA_PTR, MRI_SHORT_PTR, mri_zero_image, FD_brick::n1, FD_brick::n2, FD_brick::n3, THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, THD_3dim_dataset::taxis, THD_fdind_to_3dind(), THD_get_voxel(), THD_load_datablock(), THD_need_brick_factor(), THD_timeof(), tt, THD_timeaxis::ttdel, typ, UNITS_MSEC_TYPE, THD_timeaxis::units_type, MRI_IMAGE::xo, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_brick_to_mri().

00020 {
00021    MRI_IMAGE * im ;  /* output */
00022    int nv , ival ;
00023    char * iar ;      /* brick in the input */
00024    MRI_TYPE typ ;
00025    int ix,jy,kz , ind ;
00026    THD_ivec3 ind_fd , ind_ds ;
00027 
00028    if( ixyz < 0 || ixyz >= br->n1 * br->n2 * br->n3 ) return NULL ;
00029 
00030    /** otherwise, get ready for a real image **/
00031 
00032    ix  = ixyz % br->n1 ;
00033    jy  = ( ixyz % (br->n1 * br->n2) ) / br->n1 ;
00034    kz  = ixyz / (br->n1 * br->n2) ;
00035    LOAD_IVEC3( ind_fd , ix,jy,kz ) ; ind_ds = THD_fdind_to_3dind( br , ind_fd ) ;
00036    ix  = ind_ds.ijk[0] ;
00037    jy  = ind_ds.ijk[1] ;
00038    kz  = ind_ds.ijk[2] ;
00039    ind = (kz * br->dset->daxes->nyy + jy) * br->dset->daxes->nxx + ix ;
00040 
00041    nv = br->dset->dblk->nvals ;
00042 
00043    iar = DSET_ARRAY(br->dset,0) ;
00044    if( iar == NULL ){  /* if data needs to be loaded from disk */
00045       (void) THD_load_datablock( br->dset->dblk ) ;
00046       iar = DSET_ARRAY(br->dset,0) ;
00047       if( iar == NULL ) return NULL ;
00048    }
00049 
00050    /* 15 Sep 2004: allow for nonconstant datum */
00051 
00052    if( !DSET_datum_constant(br->dset) ){  /* only for stupid users */
00053      float *ar ;
00054      im = mri_new( nv , 1 , MRI_float ) ; ar = MRI_FLOAT_PTR(im) ;
00055      for( ival = 0 ; ival < nv ; ival++ )
00056        ar[ival] = THD_get_voxel( br->dset , ind , ival ) ;
00057      goto image_done ;
00058    }
00059 
00060    /* the older (more efficient) way */
00061 
00062    typ = DSET_BRICK_TYPE(br->dset,0) ;
00063    im  = mri_new( nv , 1 , typ ) ;
00064 #if 0
00065    mri_zero_image(im) ;             /* 18 Oct 2001 */
00066 #endif
00067 
00068    switch( typ ){
00069 
00070       default:             /* don't know what to do --> return nada */
00071          mri_free( im ) ;
00072          return NULL ;
00073 
00074       case MRI_byte:{
00075          byte * ar  = MRI_BYTE_PTR(im) , * bar ;
00076          for( ival=0 ; ival < nv ; ival++ ){
00077             bar = (byte *) DSET_ARRAY(br->dset,ival) ;
00078             if( bar != NULL ) ar[ival] = bar[ind] ;
00079          }
00080       }
00081       break ;
00082 
00083       case MRI_short:{
00084          short * ar  = MRI_SHORT_PTR(im) , * bar ;
00085          for( ival=0 ; ival < nv ; ival++ ){
00086             bar = (short *) DSET_ARRAY(br->dset,ival) ;
00087             if( bar != NULL ) ar[ival] = bar[ind] ;
00088          }
00089       }
00090       break ;
00091 
00092       case MRI_float:{
00093          float * ar  = MRI_FLOAT_PTR(im) , * bar ;
00094          for( ival=0 ; ival < nv ; ival++ ){
00095             bar = (float *) DSET_ARRAY(br->dset,ival) ;
00096             if( bar != NULL ) ar[ival] = bar[ind] ;
00097          }
00098       }
00099       break ;
00100 
00101       case MRI_int:{
00102          int * ar  = MRI_INT_PTR(im) , * bar ;
00103          for( ival=0 ; ival < nv ; ival++ ){
00104             bar = (int *) DSET_ARRAY(br->dset,ival) ;
00105             if( bar != NULL ) ar[ival] = bar[ind] ;
00106          }
00107       }
00108       break ;
00109 
00110       case MRI_double:{
00111          double * ar  = MRI_DOUBLE_PTR(im) , * bar ;
00112          for( ival=0 ; ival < nv ; ival++ ){
00113             bar = (double *) DSET_ARRAY(br->dset,ival) ;
00114             if( bar != NULL ) ar[ival] = bar[ind] ;
00115          }
00116       }
00117       break ;
00118 
00119       case MRI_complex:{
00120          complex * ar  = MRI_COMPLEX_PTR(im) , * bar ;
00121          for( ival=0 ; ival < nv ; ival++ ){
00122             bar = (complex *) DSET_ARRAY(br->dset,ival) ;
00123             if( bar != NULL ) ar[ival] = bar[ind] ;
00124          }
00125       }
00126       break ;
00127 
00128       /* 15 Apr 2002: RGB types */
00129 
00130       case MRI_rgb:{
00131          rgbyte *ar  = (rgbyte *) MRI_RGB_PTR(im) , *bar ;
00132          for( ival=0 ; ival < nv ; ival++ ){
00133             bar = (rgbyte *) DSET_ARRAY(br->dset,ival) ;
00134             if( bar != NULL ) ar[ival] = bar[ind] ;
00135          }
00136       }
00137       break ;
00138 
00139       case MRI_rgba:{
00140          rgba *ar  = (rgba *) MRI_RGBA_PTR(im) , *bar ;
00141          for( ival=0 ; ival < nv ; ival++ ){
00142             bar = (rgba *) DSET_ARRAY(br->dset,ival) ;
00143             if( bar != NULL ) ar[ival] = bar[ind] ;
00144          }
00145       }
00146       break ;
00147 
00148    }
00149 
00150    if( THD_need_brick_factor(br->dset) ){
00151       MRI_IMAGE * qim ;
00152       qim = mri_mult_to_float( br->dset->dblk->brick_fac , im ) ;
00153       mri_free(im) ; im = qim ;
00154    }
00155 
00156    /* at this point, the image is ready to ship out;
00157       but first, maybe attach a time origin and spacing */
00158 
00159 image_done:
00160    if( br->dset->taxis != NULL ){  /* 21 Oct 1996 */
00161       float zz , tt ;
00162 
00163       zz = br->dset->daxes->zzorg + kz * br->dset->daxes->zzdel ;
00164       tt = THD_timeof( 0 , zz , br->dset->taxis ) ;
00165 
00166       im->xo = tt ; im->dx = br->dset->taxis->ttdel ;   /* origin and delta */
00167 
00168       if( br->dset->taxis->units_type == UNITS_MSEC_TYPE ){ /* convert to sec */
00169          im->xo *= 0.001 ; im->dx *= 0.001 ;
00170       }
00171    } else {
00172       im->xo = 0.0 ; im->dx = 1.0 ;  /* 08 Nov 1996 */
00173    }
00174 
00175    return im ;
00176 }

void fft_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 61 of file thd_shift2.c.

References CEXPIT, CMULT, csfft_cox(), ENTRY, free, complex::i, malloc, and complex::r.

Referenced by SHIFT_set_method().

00062 {
00063    static int nupold=0 , nuptop=0 ;
00064    static complex * row=NULL , * cf=NULL , * cg=NULL ;
00065 
00066    int ii , nby2=nup/2 , n21=nby2+1 ;
00067    complex fac , gac ;
00068    float sf , sg , dk ;
00069 #ifdef RECUR
00070    complex csf , csg ;
00071 #endif
00072 
00073 ENTRY("fft_shift2") ;
00074 
00075    /* 15 Mar 2001: shift too big ==> return all zeros */
00076 
00077    if( (af < -n || af > n) && (ag < -n || ag > n) ){
00078       for( ii=0 ; ii < n ; ii++ ) f[ii] = g[ii] = 0.0 ;
00079       EXRETURN ;
00080    }
00081 
00082    /* make new memory for row storage? */
00083 
00084    if( nup > nuptop ){
00085       if( row != NULL ){ free(row) ; free(cf) ; free(cg) ; }
00086       row = (complex *) malloc( sizeof(complex) * nup ) ;
00087       cf  = (complex *) malloc( sizeof(complex) * n21 ) ;
00088       cg  = (complex *) malloc( sizeof(complex) * n21 ) ;
00089       nuptop = nup ;
00090    }
00091 
00092    /* FFT the pair of rows */
00093 
00094    if( g != NULL )
00095       for( ii=0 ; ii < n ; ii++ ){ row[ii].r = f[ii] ; row[ii].i = g[ii] ; }
00096    else
00097       for( ii=0 ; ii < n ; ii++ ){ row[ii].r = f[ii] ; row[ii].i = 0 ; }
00098 
00099 #ifdef ZFILL
00100    for( ii=n ; ii < nup ; ii++ ){ row[ii].r = row[ii].i = 0.0 ; }
00101 #else
00102    if( nup > n ){
00103       sf = 0.5 * (row[0].r + row[n-1].r) ; sg = 0.5 * (row[0].i + row[n-1].i) ;
00104       for( ii=n ; ii < nup ; ii++ ){ row[ii].r = sf ; row[ii].i = sg ; }
00105    }
00106 #endif
00107 
00108    csfft_cox( -1 , nup , row ) ;
00109 
00110    /* untangle FFT coefficients from row into cf,cg */
00111 
00112    cf[0].r = 2.0 * row[0].r ; cf[0].i = 0.0 ;  /* twice too big */
00113    cg[0].r = 2.0 * row[0].i ; cg[0].i = 0.0 ;
00114    for( ii=1 ; ii < nby2 ; ii++ ){
00115       cf[ii].r =  row[ii].r + row[nup-ii].r ;
00116       cf[ii].i =  row[ii].i - row[nup-ii].i ;
00117       cg[ii].r =  row[ii].i + row[nup-ii].i ;
00118       cg[ii].i = -row[ii].r + row[nup-ii].r ;
00119    }
00120    cf[nby2].r = 2.0 * row[nby2].r ; cf[nby2].i = 0.0 ;
00121    cg[nby2].r = 2.0 * row[nby2].i ; cg[nby2].i = 0.0 ;
00122 
00123    /* phase shift both rows (cf,cg) */
00124 
00125    dk = (2.0*PI) / nup ;
00126    sf = -af * dk ; sg = -ag * dk ;
00127 
00128 #ifdef RECUR
00129    csf = CEXPIT(sf) ; csg = CEXPIT(sg) ;
00130    fac.r = gac.r = 1.0 ;
00131    fac.i = gac.i = 0.0 ;
00132 #endif
00133 
00134    for( ii=1 ; ii <= nby2 ; ii++ ){
00135 #ifdef RECUR
00136       fac = CMULT( csf , fac ) ; cf[ii] = CMULT( fac , cf[ii] ) ;
00137       gac = CMULT( csg , gac ) ; cg[ii] = CMULT( gac , cg[ii] ) ;
00138 #else
00139       fac = CEXPIT(ii*sf) ; cf[ii] = CMULT( fac , cf[ii] ) ;
00140       gac = CEXPIT(ii*sg) ; cg[ii] = CMULT( gac , cg[ii] ) ;
00141 #endif
00142    }
00143    cf[nby2].i = 0.0 ; cg[nby2].i = 0.0 ;
00144 
00145    /* retangle the coefficients from 2 rows */
00146 
00147    row[0].r = cf[0].r ; row[0].i = cg[0].r ;
00148    for( ii=1 ; ii < nby2 ; ii++ ){
00149       row[ii].r     =  cf[ii].r - cg[ii].i ;
00150       row[ii].i     =  cf[ii].i + cg[ii].r ;
00151       row[nup-ii].r =  cf[ii].r + cg[ii].i ;
00152       row[nup-ii].i = -cf[ii].i + cg[ii].r ;
00153    }
00154    row[nby2].r = cf[nby2].r ;
00155    row[nby2].i = cg[nby2].r ;
00156 
00157    /* inverse FFT and store back in output arrays */
00158 
00159    csfft_cox( 1 , nup , row ) ;
00160 
00161    sf = 0.5 / nup ;              /* 0.5 to allow for twice too big above */
00162 
00163    if( g != NULL )
00164       for( ii=0; ii < n; ii++ ){ f[ii] = sf*row[ii].r; g[ii] = sf*row[ii].i; }
00165    else
00166       for( ii=0; ii < n; ii++ ){ f[ii] = sf*row[ii].r; }
00167 
00168    EXRETURN ;
00169 }

void free_Tmask Tmask  
 

Definition at line 8 of file extor.c.

References free, and Tmask::mask.

Referenced by CREN_render(), CREN_set_databytes(), and destroy_CREN_renderer().

00009 {
00010    if( tm != NULL ){
00011       free(tm->mask[0]) ; free(tm->mask[1]) ; free(tm->mask[2]) ; free(tm) ;
00012    }
00013    return ;
00014 }

void freeup_strings int    n,
char **    sar
 

Definition at line 61 of file thd_strfunc.c.

References free.

Referenced by AFNI_drive_addto_graph_1D(), AFNI_drive_addto_graph_xy(), AFNI_drive_clear_graph_1D(), AFNI_drive_clear_graph_xy(), AFNI_drive_close_graph_xy(), AFNI_drive_geom_graph(), AFNI_drive_open_graph_1D(), AFNI_drive_open_graph_xy(), and TTRR_load_file().

00062 {
00063    int ii ;
00064    if( sar == NULL ) return ;
00065    for( ii=0 ; ii < n ; ii++ )
00066       if( sar[ii] != NULL ) free(sar[ii]) ;
00067    free(sar) ;
00068    return ;
00069 }

void get_linear_trend int   ,
float *   ,
float *   ,
float *   
 

Definition at line 27 of file thd_detrend.c.

References x0.

Referenced by absfft_func(), linear_filter_trend(), and THD_linear_detrend().

00028 {
00029    double t1,t3,t10 , x0,x1 ;
00030    int ii ;
00031 
00032    if( npt < 2 || xx == NULL || f0 == NULL || f1 == NULL ) return ;
00033 
00034    x0 = xx[0] ; x1 = 0.0 ;
00035    for( ii=1 ; ii < npt ; ii++ ){
00036       x0 += xx[ii] ;
00037       x1 += xx[ii] * ii ;
00038    }
00039 
00040    t1 = npt*x0; t3 = 1.0/npt; t10 = npt*npt;
00041 
00042    *f0 = (float)(2.0/(npt+1.0)*t3*(2.0*t1-3.0*x1-x0));
00043    *f1 = (float)(-6.0/(t10-1.0)*t3*(-x0-2.0*x1+t1));
00044    return ;
00045 }

void get_quadratic_trend int   ,
float *   ,
float *   ,
float *   ,
float *   
 

Definition at line 76 of file thd_detrend.c.

References x0, and x2.

Referenced by THD_quadratic_detrend().

00077 {
00078    double  x0,x1,x2 , N=npt ;
00079    int ii ;
00080 
00081    if( npt < 3 || xx == NULL || f0 == NULL || f1 == NULL || f2 == NULL ) return;
00082 
00083    x0 = xx[0] ; x1 = x2 = 0.0 ;
00084    for( ii=1 ; ii < npt ; ii++ ){
00085      x0 +=  xx[ii] ;
00086      x1 += (xx[ii] * ii) ;
00087      x2 += (xx[ii] * ii) * ii ;
00088    }
00089 
00090    *f0 = (  3.0*(3.0*N*N-3.0*N+2.0) * x0
00091           -18.0*(-1.0+2.0*N)        * x1
00092           +30.0                     * x2 ) / (N*(N+2.0)*(N+1.0)) ;
00093 
00094    *f1 = ( -18.0*(-1.0+2.0*N)              * x0
00095            +12.0*(-1.0+2.0*N)*(8.0*N-11.0) * x1 /((N-1.0)*(N-2.0))
00096            -180.0                          * x2 /(N-2.0)          )
00097         / (N*(N+2.0)*(N+1.0)) ;
00098 
00099    *f2 = ( 30.0  * x0
00100           -180.0 * x1 / (N-2.0)
00101           +180.0 * x2 / ((N-1.0)*(N-2.0)) ) / (N*(N+2.0)*(N+1.0))  ;
00102    return ;
00103 }

void hept_shift int   ,
float   ,
float *   
 

Definition at line 207 of file thd_shift2.c.

References ENTRY, FINS, free, lcbuf, malloc, nlcbuf, S_00, S_M1, S_M2, S_M3, S_P1, S_P2, S_P3, and S_P4.

Referenced by hept_shift2().

00208 {
00209    int   ii , ia , ix ;
00210    float  wt_m1,wt_00,wt_p1,wt_p2 , aa , wt_m2,wt_p3,wt_m3,wt_p4;
00211 #ifdef SEPARATE_FINS
00212    int ibot,itop ;
00213 #endif
00214 
00215 ENTRY("hept_shift") ;
00216 
00217    af = -af ; ia = (int) af ; if( af < 0 ) ia-- ;  /* ia = floor */
00218 
00219    /* 15 Mar 2001: if shift is too large, return all zeros */
00220 
00221    if( ia <= -n || ia >= n ){
00222       for( ii=0 ; ii < n ; ii++ ) f[ii] = 0.0 ;
00223       EXRETURN ;
00224    }
00225 
00226    aa = af - ia ;
00227    wt_m1 = S_M1(aa) ; wt_00 = S_00(aa) ;
00228    wt_p1 = S_P1(aa) ; wt_p2 = S_P2(aa) ;
00229    wt_m2 = S_M2(aa) ; wt_p3 = S_P3(aa) ;
00230    wt_m3 = S_M3(aa) ; wt_p4 = S_P4(aa) ;
00231 
00232    if( n > nlcbuf ){
00233       if( lcbuf != NULL ) free(lcbuf) ;
00234       lcbuf  = (float *) malloc( sizeof(float) * n ) ;
00235       nlcbuf = n ;
00236    }
00237 
00238 #ifdef SEPARATE_FINS
00239    ibot = 3-ia ;   if( ibot < 0   ) ibot = 0 ;
00240    itop = n-5-ia ; if( itop > n-1 ) itop = n-1 ;
00241 
00242    for( ii=ibot ; ii <= itop ; ii++ ){
00243       ix = ii + ia ;
00244       lcbuf[ii] =  wt_m2 * f[ix-2] + wt_m1 * f[ix-1] + wt_00 * f[ix]
00245                  + wt_p1 * f[ix+1] + wt_p2 * f[ix+2] + wt_p3 * f[ix+3]
00246                  + wt_m3 * f[ix-3] + wt_p4 * f[ix+4] ;
00247    }
00248 
00249    if( ibot > n ) ibot = n ; /* 15 Mar 2001 */
00250    for( ii=0 ; ii < ibot ; ii++ ){
00251       ix = ii + ia ;
00252       lcbuf[ii] =  wt_m2 * FINS(ix-2) + wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00253                  + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) + wt_p3 * FINS(ix+3)
00254                  + wt_m3 * FINS(ix-3) + wt_p4 * FINS(ix+4) ;
00255    }
00256 
00257    if( itop < 0 ) itop = -1 ; /* 15 Mar 2001 */
00258    for( ii=itop+1 ; ii < n ; ii++ ){
00259       ix = ii + ia ;
00260       lcbuf[ii] =  wt_m2 * FINS(ix-2) + wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00261                  + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) + wt_p3 * FINS(ix+3)
00262                  + wt_m3 * FINS(ix-3) + wt_p4 * FINS(ix+4) ;
00263    }
00264 #else /* not SEPARATE_FINS */
00265    for( ii=0 ; ii < n ; ii++ ){
00266       ix = ii + ia ;
00267       if( ix > 1 && ix < n-3 )
00268          lcbuf[ii] =  wt_m2 * f[ix-2] + wt_m1 * f[ix-1] + wt_00 * f[ix]
00269                     + wt_p1 * f[ix+1] + wt_p2 * f[ix+2] + wt_p3 * f[ix+3]
00270                     + wt_m3 * f[ix-3] + wt_p4 * f[ix+4] ;
00271       else
00272          lcbuf[ii] =  wt_m2 * FINS(ix-2) + wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00273                     + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) + wt_p3 * FINS(ix+3)
00274                     + wt_m3 * FINS(ix-3) + wt_p4 * FINS(ix+4) ;
00275    }
00276 #endif /* SEPARATE_FINS */
00277 
00278    memcpy( f , lcbuf , sizeof(float)*n ) ;
00279    EXRETURN ;
00280 }

void hept_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 282 of file thd_shift2.c.

References hept_shift().

Referenced by SHIFT_set_method().

00283 {
00284                    hept_shift( n , af , f ) ;
00285    if( g != NULL ) hept_shift( n , ag , g ) ;
00286    return ;
00287 }

char* ig_strstr char *    haystack,
char *    needle,
char *    ignore
 

Find if needle is in haystack, ignoring case and ignoring any characters in ignore.

Definition at line 7 of file thd_strfunc.c.

References free.

Referenced by TTRR_load_file().

00008 {
00009    char *hs, *ne , *cp ;
00010    int ii, jj ;
00011 
00012    if( haystack == NULL || haystack[0] == '\0' ||
00013        needle   == NULL || needle[0]   == '\0'   ) return NULL ;
00014 
00015    /* make uppercase copy of haystack */
00016 
00017    hs = strdup(haystack) ; jj = strlen(hs) ;
00018    for( ii=0 ; ii < jj ; ii++ ) hs[ii] = toupper(hs[ii]) ;
00019 
00020    /* replace all ignore characters in hs with a period */
00021 
00022    if( ignore != NULL && ignore[0] != '\0' ){
00023      for( ii=0 ; ii < jj ; ii++ ){
00024        if( strchr(ignore,hs[ii]) != NULL ) hs[ii] = '.' ;
00025      }
00026    }
00027 
00028    /* make uppercase copy of needle */
00029 
00030    ne = strdup(needle) ; jj = strlen(ne) ;
00031    for( ii=0 ; ii < jj ; ii++ ) ne[ii] = toupper(ne[ii]) ;
00032 
00033    /* replace all ignore characters in ne with a period */
00034 
00035    if( ignore != NULL && ignore[0] != '\0' ){
00036      for( ii=0 ; ii < jj ; ii++ ){
00037        if( strchr(ignore,ne[ii]) != NULL ) ne[ii] = '.' ;
00038      }
00039    }
00040 
00041    /* now find if mangled needle is in the mangled haystack */
00042 
00043    cp = strstr( hs , ne ) ;
00044 
00045    /* if it is, then find corresponding location in original haystack */
00046 
00047    if( cp != NULL ){
00048      jj = cp-hs ;            /* pointer arithmetic */
00049      cp = haystack + jj ;    /* ditto */
00050    }
00051 
00052    /* we're outta here */
00053 
00054    free(ne); free(hs); return cp;
00055 }

void lin_shift int   ,
float   ,
float *   
 

Definition at line 470 of file thd_shift2.c.

References ENTRY, FINS, free, lcbuf, malloc, nlcbuf, and STATUS.

Referenced by lin_shift2().

00471 {
00472    int   ii , ia , ix ;
00473    float  wt_00 , wt_p1 , aa ;
00474 #ifdef SEPARATE_FINS
00475    int ibot,itop ;
00476 #endif
00477 
00478 ENTRY("lin_shift") ;
00479 
00480    af = -af ; ia = (int) af ; if( af < 0 ) ia-- ;  /* ia = floor */
00481    aa = af - ia ;
00482    wt_00 = 1.0 - aa ; wt_p1 = aa ;  /* linear interpolation weights */
00483 
00484    /* 15 Mar 2001: if shift is too large, return all zeros */
00485 
00486    if( ia <= -n || ia >= n ){
00487       for( ii=0 ; ii < n ; ii++ ) f[ii] = 0.0 ;
00488       EXRETURN ;
00489    }
00490 
00491    if( n > nlcbuf ){
00492       if( lcbuf != NULL ) free(lcbuf) ;
00493       lcbuf  = (float *) malloc( sizeof(float) * n ) ;
00494       nlcbuf = n ;
00495    }
00496 
00497 #ifdef SEPARATE_FINS
00498    ibot = -ia  ;   if( ibot < 0   ) ibot = 0 ;
00499    itop = n-2-ia ; if( itop > n-1 ) itop = n-1 ;
00500 
00501 #if 0
00502 if(PRINT_TRACING){
00503   char str[256]; sprintf(str,"n=%d ia=%d ibot=%d itop=%d",n,ia,ibot,itop); STATUS(str);
00504 }
00505 #endif
00506 
00507    for( ii=ibot ; ii <= itop ; ii++ ){
00508       ix = ii + ia ;
00509       lcbuf[ii] =  wt_00 * f[ix] + wt_p1 * f[ix+1] ;
00510    }
00511 
00512    if( ibot > n ) ibot = n ; /* 15 Mar 2001 */
00513    for( ii=0 ; ii < ibot ; ii++ ){
00514       ix = ii + ia ;
00515       lcbuf[ii] =  wt_00 * FINS(ix) + wt_p1 * FINS(ix+1) ;
00516    }
00517 
00518    if( itop < 0 ) itop = -1 ; /* 15 Mar 2001 */
00519    for( ii=itop+1 ; ii < n ; ii++ ){
00520       ix = ii + ia ;
00521       lcbuf[ii] =  wt_00 * FINS(ix) + wt_p1 * FINS(ix+1) ;
00522    }
00523 #else
00524    for( ii=0 ; ii < n ; ii++ ){
00525       ix = ii + ia ;
00526       if( ix >= 0 && ix < n-1 )
00527          lcbuf[ii] =  wt_00 * f[ix] + wt_p1 * f[ix+1] ;
00528       else
00529          lcbuf[ii] =  wt_00 * FINS(ix) + wt_p1 * FINS(ix+1) ;
00530    }
00531 #endif /* SEPARATE_FINS */
00532 
00533    memcpy( f , lcbuf , sizeof(float)*n ) ;
00534    EXRETURN ;
00535 }

void lin_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 537 of file thd_shift2.c.

References lin_shift().

Referenced by SHIFT_set_method().

00538 {
00539                    lin_shift( n , af , f ) ;
00540    if( g != NULL ) lin_shift( n , ag , g ) ;
00541    return ;
00542 }

int* MCW_get_intlist int    nvals,
char *    str
 

Get an integer list in the range 0..(nvals-1), from the character string str. If we call the output pointer fred, then fred[0] = number of integers in the list (> 0), and fred[i] = i-th integer in the list for i=1..fred[0]. If on return, fred == NULL or fred[0] == 0, then something is wrong, and the caller must deal with that.

Syntax of input string:

  • initial '{' or '[' is skipped, if present
  • ends when '}' or ']' or end of string is found
  • contains entries separated by commas
  • entries have one of these forms:
    • a single number
    • a dollar sign '$', which means nvals-1
    • a sequence of consecutive numbers in the form "a..b" or "a-b", where "a" and "b" are single numbers (or '$')
    • a sequence of evenly spaced numbers in the form "a..b(c)" or "a-b(c)", where "c" encodes the step
  • Example: "[2,7..4,3..9(2)]" decodes to the list 2 7 6 5 4 3 5 7 9
  • entries should be in the range 0..nvals-1 -------------------------------------------------------------------

Definition at line 46 of file thd_intlist.c.

References allow_negative, free, ISEND, malloc, and realloc.

Referenced by CALC_read_opts(), main(), mri_read_1D(), SYM_expand_ranges(), and THD_open_dataset().

00047 {
00048    int *subv = NULL ;
00049    int ii , ipos , nout , slen ;
00050    int ibot,itop,istep , nused ;
00051    char *cpt ;
00052 
00053    /* Meaningless input? */
00054 
00055    if( nvals < 1 ) return NULL ;
00056 
00057    /* No selection list? */
00058 
00059    if( str == NULL || str[0] == '\0' ) return NULL ;
00060 
00061    /* skip initial '[' or '{' */
00062 
00063    subv    = (int *) malloc( sizeof(int) * 2 ) ;
00064    subv[0] = nout = 0 ;
00065 
00066    ipos = 0 ;
00067    if( str[ipos] == '[' || str[ipos] == '{' ) ipos++ ;
00068 
00069    /*** loop through each sub-selector until end of input ***/
00070 
00071    slen = strlen(str) ;
00072    while( ipos < slen && !ISEND(str[ipos]) ){
00073 
00074       while( isspace(str[ipos]) ) ipos++ ;   /* skip blanks */
00075       if( ISEND(str[ipos]) ) break ;         /* done */
00076 
00077       /** get starting value **/
00078 
00079       if( str[ipos] == '$' ){  /* special case */
00080          ibot = nvals-1 ; ipos++ ;
00081       } else {                 /* decode an integer */
00082          ibot = strtol( str+ipos , &cpt , 10 ) ;
00083          if( ibot < 0 && !allow_negative ){
00084            fprintf(stderr,"** ERROR: sub-brick index %d is out of range 0..%d\n",
00085                    ibot,nvals-1) ;
00086            free(subv) ; return NULL ;
00087          }
00088          if( ibot >= nvals ){
00089            fprintf(stderr,"** ERROR: sub-brick index %d is out of range 0..%d\n",
00090                    ibot,nvals-1) ;
00091            free(subv) ; return NULL ;
00092          }
00093          nused = (cpt-(str+ipos)) ;
00094          if( ibot == 0 && nused == 0 ){
00095            fprintf(stderr,"** ERROR: sub-brick syntax error '%s'\n",str+ipos) ;
00096            free(subv) ; return NULL ;
00097          }
00098          ipos += nused ;
00099       }
00100 
00101       while( isspace(str[ipos]) ) ipos++ ;   /* skip blanks */
00102 
00103       /** if that's it for this sub-selector, add one value to list **/
00104 
00105       if( str[ipos] == ',' || ISEND(str[ipos]) ){
00106          nout++ ;
00107          subv = (int *) realloc( (char *)subv , sizeof(int) * (nout+1) ) ;
00108          subv[0]    = nout ;
00109          subv[nout] = ibot ;
00110          if( ISEND(str[ipos]) ) break ; /* done */
00111          ipos++ ; continue ;            /* re-start loop at next sub-selector */
00112       }
00113 
00114       /** otherwise, must have '..' or '-' as next inputs **/
00115 
00116       if( str[ipos] == '-' ){
00117          ipos++ ;
00118       } else if( str[ipos] == '.' && str[ipos+1] == '.' ){
00119          ipos++ ; ipos++ ;
00120       } else {
00121          fprintf(stderr,"** ERROR: sub-brick selector syntax is bad: '%s'\n",
00122                  str+ipos) ;
00123          free(subv) ; return NULL ;
00124       }
00125 
00126       /** get ending value for loop now **/
00127 
00128       if( str[ipos] == '$' ){  /* special case */
00129          itop = nvals-1 ; ipos++ ;
00130       } else {                 /* decode an integer */
00131          itop = strtol( str+ipos , &cpt , 10 ) ;
00132          if( itop < 0 && !allow_negative ){
00133            fprintf(stderr,"** ERROR: sub-brick index %d is out of range 0..%d\n",
00134                    itop,nvals-1) ;
00135            free(subv) ; return NULL ;
00136          }
00137          if( itop >= nvals ){
00138            fprintf(stderr,"** ERROR: sub-brick index %d is out of range 0..%d\n",
00139                    itop,nvals-1) ;
00140            free(subv) ; return NULL ;
00141          }
00142          nused = (cpt-(str+ipos)) ;
00143          if( itop == 0 && nused == 0 ){
00144            fprintf(stderr,"** ERROR: sub-brick syntax error '%s'\n",str+ipos) ;
00145            free(subv) ; return NULL ;
00146          }
00147          ipos += nused ;
00148       }
00149 
00150       /** set default loop step **/
00151 
00152       istep = (ibot <= itop) ? 1 : -1 ;
00153 
00154       while( isspace(str[ipos]) ) ipos++ ;                  /* skip blanks */
00155 
00156       /** check if we have a non-default loop step **/
00157 
00158       if( str[ipos] == '(' ){  /* decode an integer */
00159          ipos++ ;
00160          istep = strtol( str+ipos , &cpt , 10 ) ;
00161          if( istep == 0 ){
00162            fprintf(stderr,"** ERROR: sub-brick loop step is 0!\n") ;
00163            free(subv) ; return NULL ;
00164          }
00165          nused = (cpt-(str+ipos)) ;
00166          ipos += nused ;
00167          if( str[ipos] == ')' ) ipos++ ;
00168          if( (ibot-itop)*istep > 0 ){
00169            fprintf(stderr,"** WARNING: sub-brick count '%d..%d(%d)' means nothing!\n",
00170                    ibot,itop,istep ) ;
00171          }
00172       }
00173 
00174       /** add values to output **/
00175 
00176       for( ii=ibot ; (ii-itop)*istep <= 0 ; ii += istep ){
00177          nout++ ;
00178          subv = (int *) realloc( (char *)subv , sizeof(int) * (nout+1) ) ;
00179          subv[0]    = nout ;
00180          subv[nout] = ii ;
00181       }
00182 
00183       /** check if we have a comma to skip over **/
00184 
00185       while( isspace(str[ipos]) ) ipos++ ;                  /* skip blanks */
00186       if( str[ipos] == ',' ) ipos++ ;                       /* skip commas */
00187 
00188    }  /* end of loop through selector string */
00189 
00190    if( subv[0] == 0 ){ free(subv); subv = NULL; }
00191    return subv ;
00192 }

void MCW_hash_idcode char *   ,
struct THD_3dim_dataset  
 

void MCW_intlist_allow_negative int    iii
 

Allow negative indexes in MCW_get_intlist()

Definition at line 13 of file thd_intlist.c.

References allow_negative.

Referenced by CALC_read_opts(), and SYM_expand_ranges().

00014 {
00015    allow_negative = iii ; return ;
00016 }

char* MD5_B64_array int    n,
char *    bytes
 

Return the MD5 hash of an array as a Base64 string, instead of a hex string. strlen(result) is 22 instead of 32 result is malloc()-ed and should be free()-d when appropriate ------------------------------------------------------------------------------

Definition at line 466 of file niml_md5.c.

00467 {
00468    MD5_CTX context;
00469    unsigned char digest[16];
00470 
00471    if( n < 0 || bytes == NULL ) return NULL ;
00472 
00473    MD5Init( &context ) ;
00474    MD5Update( &context, (unsigned char *)bytes, n ) ;
00475    MD5Final( digest, &context ) ;
00476 
00477    return MD5_to_B64( digest ) ;
00478 }

char* MD5_B64_file char *    filename
 

Return the MD5 hash of a file as a Base64 string, instead of a hex string.

  • strlen(result) is 22 instead of 32
  • result is malloc()-ed and should be free()-d when appropriate ------------------------------------------------------------------------------

Definition at line 500 of file niml_md5.c.

00501 {
00502   FILE *file;
00503   MD5_CTX context;
00504   int len;
00505   unsigned char buffer[1024] ;
00506   unsigned char digest[16] ;
00507 
00508   if( (file=fopen (filename, "rb")) == NULL ) return NULL ;
00509 
00510   MD5Init( &context ) ;
00511 
00512   while( len = fread(buffer, 1, 1024, file) )
00513       MD5Update( &context, buffer, len ) ;
00514 
00515   MD5Final( digest, &context );
00516   fclose (file);
00517 
00518   return MD5_to_B64( digest ) ;
00519 }

char* MD5_B64_string char *    string
 

Return the MD5 hash of a C string as a Base64 string, instead of a hex string. strlen(result) is 22 instead of 32 result is malloc()-ed and should be free()-d when appropriate ------------------------------------------------------------------------------

Definition at line 487 of file niml_md5.c.

00488 {
00489    if( string == NULL ) string = "ElvisTheKing" ;
00490    return MD5_B64_array( strlen(string) , string ) ;
00491 }

char* MD5_malloc_array int    n,
char *    bytes
 

Digest an array and returns the printable string of the result, stored in a malloc()-ed array (length=32+1 bytes). ------------------------------------------------------------------------

Definition at line 372 of file niml_md5.c.

00373 {
00374    char *st , *dy ;
00375    st = MD5_static_array( n , bytes ) ;
00376    if( st == NULL ) return NULL ;
00377    dy = (char *) malloc(33) ; strcpy(dy,st) ; return dy ;
00378 }

char* MD5_malloc_file char *    filename
 

Digests a file and prints the result, stored in a malloc()-ed array (length=32+1 bytes). ------------------------------------------------------------------------

Definition at line 433 of file niml_md5.c.

00434 {
00435    char *st , *dy ;
00436 
00437    st = MD5_static_file( filename ) ;
00438    if( st == NULL ) return NULL ;
00439    dy = (char *) malloc(33) ; strcpy(dy,st) ; return dy ;
00440 }

char* MD5_malloc_string char *    string
 

Digest a C string and returns the printable string of the result, stored in a malloc()-ed array (length=32+1 bytes). ------------------------------------------------------------------------

Definition at line 396 of file niml_md5.c.

00397 {
00398    if( string == NULL ) string = "ElvisTheKing" ;
00399    return MD5_malloc_array( strlen(string)+1 , string ) ;
00400 }

char* MD5_static_array int    n,
char *    bytes
 

Digest an array and returns the printable string of the result, stored in a static array (length=32+1 bytes). ------------------------------------------------------------------------

Definition at line 353 of file niml_md5.c.

00354 {
00355    MD5_CTX context;
00356    unsigned char digest[16];
00357 
00358    if( n < 0 || bytes == NULL ) return NULL ;
00359 
00360    MD5Init( &context ) ;
00361    MD5Update( &context, (unsigned char *)bytes, n ) ;
00362    MD5Final( digest, &context ) ;
00363 
00364    return MD5_static_printf(digest) ;
00365 }

char* MD5_static_file char *    filename
 

Digests a file and prints the result, stored in a static array (length=32+1 bytes). ------------------------------------------------------------------------

Definition at line 407 of file niml_md5.c.

00408 {
00409   FILE *file;
00410   MD5_CTX context;
00411   int len;
00412   unsigned char buffer[1024] ;
00413   unsigned char digest[16] ;
00414 
00415   if( (file = fopen(filename, "rb")) == NULL ) return NULL ;
00416 
00417   MD5Init( &context ) ;
00418 
00419   while( len = fread(buffer, 1, 1024, file) )
00420       MD5Update( &context, buffer, len ) ;
00421 
00422   MD5Final( digest, &context );
00423   fclose (file);
00424 
00425   return MD5_static_printf( digest ) ;
00426 }

char* MD5_static_string char *    string
 

Digest a C string and returns the printable string of the result, stored in a static array (length=32+1 bytes). ------------------------------------------------------------------------

Definition at line 385 of file niml_md5.c.

00386 {
00387    if( string == NULL ) string = "ElvisTheKing" ;
00388    return MD5_static_array( strlen(string) , string ) ;
00389 }

void mri_3dalign_cleanup MRI_3dalign_basis  
 

Definition at line 701 of file mri_3dalign.c.

References MRI_3dalign_basis::chol_fitim, DESTROY_IMARR, ENTRY, MRI_3dalign_basis::fitim, and free.

Referenced by cleanup_rtinp(), mri_3dalign_many(), RT_registration_3D_close(), and VOLREG_main().

00702 {
00703 ENTRY("mri_3dalign_cleanup") ;
00704    if( basis == NULL ) EXRETURN ;
00705 
00706    if( basis->fitim      != NULL ){ DESTROY_IMARR( basis->fitim ) ; }
00707    if( basis->chol_fitim != NULL ){ free(basis->chol_fitim) ; }
00708 
00709    free(basis) ; EXRETURN ;
00710 }

void mri_3dalign_edging int   ,
int   ,
int   
 

Definition at line 137 of file mri_3dalign.c.

References xedge, yedge, and zedge.

00138 {
00139    xedge = x ; yedge = y ; zedge = z ;
00140 }

void mri_3dalign_edging_default int   ,
int   ,
int   
 

Definition at line 147 of file mri_3dalign.c.

References MIN, my_getenv(), nz, strtod(), xfade, yfade, and zfade.

Referenced by mri_3dalign_setup().

00148 {
00149    char *ef=my_getenv("AFNI_VOLREG_EDGING") , *eq ;
00150 
00151    if( ef == NULL ){                  /* the 5% solution */
00152       xfade = (int)(0.05*nx+0.5) ;
00153       yfade = (int)(0.05*ny+0.5) ;
00154       zfade = (int)(0.05*nz+0.5) ;
00155    } else {
00156       float ff = strtod(ef,&eq) ;
00157       if( ff < 0 ){                   /* again */
00158          xfade = (int)(0.05*nx+0.5) ;
00159          yfade = (int)(0.05*ny+0.5) ;
00160          zfade = (int)(0.05*nz+0.5) ;
00161       } else {
00162          if( *eq == '%' ){            /* the whatever % solution */
00163             xfade = (int)(0.01*ff*nx+0.5) ;
00164             yfade = (int)(0.01*ff*ny+0.5) ;
00165             zfade = (int)(0.01*ff*nz+0.5) ;
00166          } else {                     /* the fixed value solution */
00167             xfade = (int)( MIN(0.25*nx,ff) ) ;
00168             yfade = (int)( MIN(0.25*ny,ff) ) ;
00169             zfade = (int)( MIN(0.25*nz,ff) ) ;
00170          }
00171       }
00172    }
00173 }

void mri_3dalign_final_regmode int   
 

Definition at line 124 of file mri_3dalign.c.

References final_regmode.

Referenced by RT_registration_3D_setup().

00125 {
00126    final_regmode = frm ;
00127    return ;
00128 }

void mri_3dalign_force_edging int   
 

Definition at line 142 of file mri_3dalign.c.

References force_edging.

00143 {
00144    force_edging = n ;
00145 }

void mri_3dalign_initvals float   ,
float   ,
float   ,
float   ,
float   ,
float   
 

Definition at line 95 of file mri_3dalign.c.

References init_dth1, init_dth2, init_dth3, init_dx, init_dy, and init_dz.

00097 {
00098    init_dth1 = th1 ; init_dth2 = th2 ; init_dth3 = th3 ;  /* degrees */
00099    init_dx   = dx  ; init_dy   = dy  ; init_dz   = dz  ;  /* mm      */
00100 }

MRI_IMARR* mri_3dalign_many MRI_IMAGE  ,
MRI_IMAGE  ,
MRI_IMARR  ,
float *   ,
float *   ,
float *   ,
float *   ,
float *   ,
float *   
 

Definition at line 670 of file mri_3dalign.c.

References ADDTO_IMARR, ENTRY, MRI_IMARR::imarr, INIT_IMARR, mri_3dalign_cleanup(), mri_3dalign_one(), mri_3dalign_setup(), MRI_IMARR::num, and RETURN.

00673 {
00674    int kim ;
00675    MRI_IMAGE * tim ;
00676    MRI_IMARR * alim ;
00677    MRI_3dalign_basis * basis ;
00678 
00679 ENTRY("mri_3dalign_many") ;
00680 
00681    basis = mri_3dalign_setup( im , imwt ) ;
00682    if( basis == NULL ) RETURN( NULL );
00683 
00684    INIT_IMARR( alim ) ;
00685 
00686 #define PK(x) ( (x!=NULL) ? (x+kim) : NULL )
00687 
00688    for( kim=0 ; kim < ims->num ; kim++ ){
00689       tim = mri_3dalign_one( basis , ims->imarr[kim] ,
00690                              PK(th1), PK(th2), PK(th3),
00691                              PK(dx) , PK(dy) , PK(dz)  ) ;
00692       ADDTO_IMARR(alim,tim) ;
00693    }
00694 
00695    mri_3dalign_cleanup( basis ) ;
00696    RETURN( alim );
00697 }

void mri_3dalign_method int   ,
int   ,
int   ,
int   
 

Definition at line 109 of file mri_3dalign.c.

References clipit, noreg, regmode, and verbose.

Referenced by RT_registration_3D_setup(), and VOLREG_main().

00110 {
00111    regmode = rmode ;
00112    verbose = verb ;
00113    noreg   = norgg ;
00114    clipit  = clip ;
00115    return ;
00116 }

MRI_IMAGE* mri_3dalign_one MRI_3dalign_basis  ,
MRI_IMAGE  ,
float *   ,
float *   ,
float *   ,
float *   ,
float *   ,
float *   
 

Definition at line 533 of file mri_3dalign.c.

References ax1, ax2, ax3, MRI_3dalign_basis::chol_fitim, clipit, dcode, DFAC, MRI_IMAGE::dx, dxy_thresh, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, fim, final_regmode, fit, MRI_3dalign_basis::fitim, free, IMTRIM, init_dth1, init_dth2, init_dth3, init_dx, init_dy, init_dz, MRI_IMAGE::kind, malloc, max_iter, MRI_CUBIC, mri_delayed_lsqfit(), MRI_FLOAT_PTR, MRI_FOURIER, mri_free(), MRI_HEPTIC, mri_max(), mri_min(), MRI_QUINTIC, mri_to_float(), noreg, MRI_IMAGE::nvox, phi_thresh, regmode, RETURN, THD_rota3D(), THD_rota_method(), and TRIM.

Referenced by mri_3dalign_many(), RT_registration_3D_onevol(), and VOLREG_main().

00536 {
00537    MRI_IMARR * fitim ;
00538    double * chol_fitim=NULL ;
00539    float * fit , *dfit ;
00540    int iter , good , ii ;
00541    float dxt , dyt , dzt , ftop,fbot ;
00542    MRI_IMAGE * tim , * fim ;
00543 
00544 ENTRY("mri_3dalign_one") ;
00545 
00546    fitim      = basis->fitim ;
00547    chol_fitim = basis->chol_fitim ;
00548 
00549    /* use original image if possible */
00550 
00551    if( im->kind == MRI_float ) fim = im ;
00552    else                        fim = mri_to_float( im ) ;
00553 
00554    iter = 0 ;
00555 
00556    THD_rota_method( regmode ) ;
00557 
00558    /* convert displacement threshold from voxels to mm in each direction */
00559 
00560    dxt = (im->dx != 0.0) ? (fabs(im->dx) * dxy_thresh) : dxy_thresh ;
00561    dyt = (im->dy != 0.0) ? (fabs(im->dy) * dxy_thresh) : dxy_thresh ;
00562    dzt = (im->dz != 0.0) ? (fabs(im->dz) * dxy_thresh) : dxy_thresh ;
00563 
00564    if( NONZERO_INITVALS ){                                    /* 04 Sep 2000 */
00565       fit = (float *) malloc(sizeof(float)*7) ;
00566       fit[0] = 1.0 ;
00567       fit[1] = init_dth1; fit[2] = init_dth2; fit[3] = init_dth3; /* degrees */
00568       fit[4] = init_dx  ; fit[5] = init_dy  ; fit[6] = init_dz  ; /* mm      */
00569 
00570       good = 1 ;
00571    } else {
00572 
00573       /* 06 Jun 2002: do initial fit with trimmed image, if ordered */
00574 
00575       if( DOTRIM ){
00576         tim = IMTRIM(fim) ;
00577         fit = mri_delayed_lsqfit( tim , fitim , chol_fitim ) ;
00578         mri_free( tim ) ;
00579       } else {                                /* L2 fit input image */
00580         fit = mri_delayed_lsqfit( fim , fitim , chol_fitim ) ;
00581       }
00582 
00583       good = ( 10.0*fabs(fit[4]) > dxt        || 10.0*fabs(fit[5]) > dyt        ||
00584                10.0*fabs(fit[6]) > dzt        || 10.0*fabs(fit[1]) > phi_thresh ||
00585                10.0*fabs(fit[2]) > phi_thresh || 10.0*fabs(fit[3]) > phi_thresh   ) ;
00586    }
00587 
00588    if( verbose )
00589       fprintf(stderr,
00590              "\nFirst fit: %13.6g %13.6g %13.6g %13.6g %13.6g %13.6g %13.6g\n",
00591              fit[0] , fit[1] , fit[2] , fit[3] , fit[4] , fit[5] , fit[6] ) ;
00592 
00593    /*-- iterate fit --*/
00594 
00595    while( good ){
00596       tim = THD_rota3D( fim ,
00597                         ax1,fit[1]*DFAC , ax2,fit[2]*DFAC , ax3,fit[3]*DFAC ,
00598                         dcode , fit[4],fit[5],fit[6] ) ;
00599 
00600       TRIM(tim) ; /* 06 Jun 2002: trim it if ordered to */
00601 
00602       dfit = mri_delayed_lsqfit( tim , fitim , chol_fitim ) ; /* delta angle/shift */
00603       mri_free( tim ) ;
00604 
00605       fit[1] += dfit[1] ; fit[2] += dfit[2] ; fit[3] += dfit[3] ;  /* accumulate  */
00606       fit[4] += dfit[4] ; fit[5] += dfit[5] ; fit[6] += dfit[6] ;  /* angle/shift */
00607 
00608       if( verbose ){
00609          fprintf(stderr,
00610                  "Delta fit: %13.6g %13.6g %13.6g %13.6g %13.6g %13.6g %13.6g\n",
00611                  dfit[0], dfit[1], dfit[2], dfit[3], dfit[4], dfit[5], dfit[6] ) ;
00612          fprintf(stderr,
00613                  "Total fit: %13.6g %13.6g %13.6g %13.6g %13.6g %13.6g %13.6g\n",
00614                  dfit[0], fit[1], fit[2], fit[3], fit[4], fit[5], fit[6] ) ;
00615       }
00616 
00617       good = (++iter < max_iter) &&
00618              ( fabs(dfit[4]) > dxt        || fabs(dfit[5]) > dyt        ||
00619                fabs(dfit[6]) > dzt        || fabs(dfit[1]) > phi_thresh ||
00620                fabs(dfit[2]) > phi_thresh || fabs(dfit[3]) > phi_thresh   ) ;
00621 
00622       free(dfit) ; dfit = NULL ;
00623    } /* end while */
00624 
00625    if( verbose ) fprintf(stderr,"Iteration complete at %d steps\n",iter) ;
00626 
00627    /*-- save final alignment parameters --*/
00628 
00629    if( th1 != NULL ) *th1 = fit[1]*DFAC ;  /* convert to radians */
00630    if( th2 != NULL ) *th2 = fit[2]*DFAC ;
00631    if( th3 != NULL ) *th3 = fit[3]*DFAC ;
00632    if( dx  != NULL ) *dx  = fit[4] ;
00633    if( dy  != NULL ) *dy  = fit[5] ;
00634    if( dz  != NULL ) *dz  = fit[6] ;
00635 
00636    /*-- do the actual realignment --*/
00637 
00638    if( ! noreg ){
00639       if( final_regmode < 0 ) final_regmode = regmode ;  /* 20 Nov 1998 */
00640       THD_rota_method( final_regmode ) ;
00641       tim = THD_rota3D( fim ,
00642                         ax1,fit[1]*DFAC , ax2,fit[2]*DFAC , ax3,fit[3]*DFAC ,
00643                         dcode , fit[4],fit[5],fit[6] ) ;
00644    } else {
00645       tim = NULL ;
00646    }
00647 
00648    if( tim != NULL && clipit &&
00649        (final_regmode == MRI_QUINTIC || final_regmode==MRI_CUBIC  ||
00650         final_regmode == MRI_HEPTIC  || final_regmode==MRI_FOURIER  ) ){
00651 
00652       register int ii ;
00653       register float ftop , fbot , * tar ;
00654 
00655       ftop = mri_max( fim ); fbot = mri_min( fim );
00656       tar  = MRI_FLOAT_PTR(tim) ;
00657       for( ii=0 ; ii < tim->nvox ; ii++ ){
00658               if( tar[ii] < fbot ) tar[ii] = fbot ;
00659          else if( tar[ii] > ftop ) tar[ii] = ftop ;
00660       }
00661    }
00662 
00663    if( fim != im ) mri_free(fim) ;  /* if it was a copy, junk it */
00664 
00665    RETURN( tim );  /* 10-4, good buddy */
00666 }

void mri_3dalign_params int   ,
float   ,
float   ,
float   ,
int   ,
int   ,
int   ,
int   
 

Definition at line 67 of file mri_3dalign.c.

References ax1, ax2, ax3, dcode, delfac, dxy_thresh, DXY_THRESH, max_iter, MAX_ITER, phi_thresh, and PHI_THRESH.

Referenced by RT_registration_3D_setup(), and VOLREG_main().

00070 {
00071    if( maxite > 0   ) max_iter    = maxite ; else max_iter    = MAX_ITER    ;
00072    if( dxy    > 0.0 ) dxy_thresh  = dxy    ; else dxy_thresh  = DXY_THRESH  ;
00073    if( dph    > 0.0 ) phi_thresh  = dph    ; else phi_thresh  = PHI_THRESH  ;
00074    if( dfac   > 0.0 ) delfac      = dfac   ;
00075 
00076    if( bx1 >= 0 && bx1 <= 2 ) ax1 = bx1 ;
00077    if( bx2 >= 0 && bx2 <= 2 ) ax2 = bx2 ;
00078    if( bx3 >= 0 && bx3 <= 2 ) ax3 = bx3 ;
00079 
00080    dcode = dc ;
00081    return ;
00082 }

void mri_3dalign_scaleinit float   
 

Definition at line 60 of file mri_3dalign.c.

References sinit.

00061 {
00062   if( ttt > 0.0 ) sinit = ttt ;
00063 }

MRI_3dalign_basis* mri_3dalign_setup MRI_IMAGE  ,
MRI_IMAGE  
 

Definition at line 185 of file mri_3dalign.c.

References ADDTO_IMARR, ax1, ax2, ax3, MRI_3dalign_basis::chol_fitim, dcode, delfac, DFAC, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, EDIT_blur_volume_3d(), ENTRY, MRI_3dalign_basis::fitim, force_edging, imbase, IMTRIM, INIT_IMARR, malloc, mri_3dalign_edging_default(), MRI_5blur_inplace_3D(), MRI_autobbox(), MRI_FLOAT_PTR, mri_free(), MRI_IS_3D, mri_max(), mri_new_conforming, mri_startup_lsqfit(), mri_to_float(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, nz, MRI_IMAGE::pixel_size, regmode, RETURN, sinit, THD_rota3D(), THD_rota_method(), TRIM, VRANG, MRI_3dalign_basis::xa, MRI_3dalign_basis::xb, xedge, xfade, MRI_3dalign_basis::ya, MRI_3dalign_basis::yb, yedge, yfade, MRI_3dalign_basis::za, MRI_3dalign_basis::zb, zedge, and zfade.

Referenced by mri_3dalign_many(), RT_registration_3D_setup(), and VOLREG_main().

00186 {
00187    MRI_IMAGE *bim , *pim , *mim , *dim , *imww , *cim ;
00188    float *dar , *par , *mar ;
00189    float delta , dx,dy,dz ;
00190    int ii ;
00191    MRI_IMARR * fitim  =NULL;
00192    double * chol_fitim=NULL ;
00193    MRI_3dalign_basis *basis = NULL ;
00194 
00195 ENTRY("mri_3dalign_setup") ;
00196 
00197    if( !MRI_IS_3D(imbase) ){
00198      fprintf(stderr,"\n*** mri_3dalign_setup: cannot use nD images!\a\n") ;
00199      RETURN( NULL );
00200    }
00201 
00202    /*--- create output struct ---*/
00203 
00204    basis = (MRI_3dalign_basis *) malloc( sizeof(MRI_3dalign_basis) ) ;
00205 
00206    /*-- local copy of input image --*/
00207 
00208    cim = mri_to_float( imbase ) ;
00209 
00210    dx = fabs(cim->dx) ; if( dx == 0.0 ) dx = 1.0 ;
00211    dy = fabs(cim->dy) ; if( dy == 0.0 ) dy = 1.0 ;
00212    dz = fabs(cim->dz) ; if( dz == 0.0 ) dz = 1.0 ;
00213 
00214    /*--- get the weighting image ---*/
00215 
00216    if( imwt != NULL &&
00217        (imwt->nx != cim->nx || imwt->ny != cim->ny || imwt->nz != cim->nz) ){
00218 
00219       fprintf(stderr,"*** WARNING: in mri_3dalign_setup, weight image mismatch!\n") ;
00220       imwt = NULL ;
00221    }
00222 
00223    /* make weight up from the base if it isn't supplied */
00224 
00225    if( imwt == NULL ){
00226       int nx=cim->nx , ny=cim->ny , nz=cim->nz , nxy = nx*ny , nxyz=nxy*nz ;
00227       int ii ;
00228       float * f , clip ;
00229 
00230       /* copy base image */
00231 
00232       imww = mri_to_float( cim ) ; f = MRI_FLOAT_PTR(imww) ;
00233 
00234       if( verbose ) fprintf(stderr,"  initializing weight") ;
00235 
00236       for( ii=0 ; ii < nxyz ; ii++ ) f[ii] = fabs(f[ii]) ;  /* 16 Nov 1998 */
00237 
00238 #if 1
00239       EDIT_blur_volume_3d( nx,ny,nz , dx,dy,dz ,
00240                            MRI_float , f , 3.0*dx , 3.0*dy , 3.0*dz ) ;
00241 #else
00242       MRI_5blur_inplace_3D( imww ) ;  /* 07 Jun 2002 */
00243 #endif
00244 
00245       if( verbose ) fprintf(stderr,":") ;
00246 
00247       clip  = 0.025 * mri_max(imww) ;
00248       for( ii=0 ; ii < nxyz ; ii++ ) if( f[ii] < clip ) f[ii] = 0.0 ;
00249 
00250    } else {
00251       imww = mri_to_float( imwt ) ;  /* just copy input weight image */
00252 
00253       if( wproc ){  /* 06 Jun 2002: process input weight */
00254         int nx=cim->nx , ny=cim->ny , nz=cim->nz , nxy = nx*ny , nxyz=nxy*nz ;
00255         int ii ;
00256         float * f , clip ;
00257 
00258         if( verbose ) fprintf(stderr,"  processing weight") ;
00259         f = MRI_FLOAT_PTR(imww) ;
00260         for( ii=0 ; ii < nxyz ; ii++ ) f[ii] = fabs(f[ii]) ;  /* 16 Nov 1998 */
00261 #if 1
00262         EDIT_blur_volume_3d( nx,ny,nz , dx,dy,dz ,
00263                              MRI_float , f , 3.0*dx , 3.0*dy , 3.0*dz ) ;
00264 #else
00265         MRI_5blur_inplace_3D( imww ) ;  /* 07 Jun 2002 */
00266 #endif
00267         if( verbose ) fprintf(stderr,":") ;
00268         clip  = 0.025 * mri_max(imww) ;
00269         for( ii=0 ; ii < nxyz ; ii++ ) if( f[ii] < clip ) f[ii] = 0.0 ;
00270       }
00271    }
00272 
00273    /*-- 10 Dec 2000: user-controlled fade out around the edges --*/
00274 
00275    if( imwt == NULL || force_edging ){
00276      int ff , ii,jj,kk ;
00277      int nx=cim->nx , ny=cim->ny , nz=cim->nz , nxy = nx*ny ;
00278      float *f = MRI_FLOAT_PTR(imww) ;
00279 
00280      xfade = xedge ; yfade = yedge ; zfade = zedge ;  /* static variables */
00281 
00282      if( xfade < 0 || yfade < 0 || zfade < 0 )
00283         mri_3dalign_edging_default(nx,ny,nz) ;        /* reassign fades */
00284 
00285 #define FF(i,j,k) f[(i)+(j)*nx+(k)*nxy]
00286 
00287       for( jj=0 ; jj < ny ; jj++ )
00288          for( ii=0 ; ii < nx ; ii++ )
00289             for( ff=0 ; ff < zfade ; ff++ )
00290                FF(ii,jj,ff) = FF(ii,jj,nz-1-ff) = 0.0 ;
00291 
00292       for( kk=0 ; kk < nz ; kk++ )
00293          for( jj=0 ; jj < ny ; jj++ )
00294             for( ff=0 ; ff < xfade ; ff++ )
00295                FF(ff,jj,kk) = FF(nx-1-ff,jj,kk) = 0.0 ;
00296 
00297       for( kk=0 ; kk < nz ; kk++ )
00298          for( ii=0 ; ii < nx ; ii++ )
00299             for( ff=0 ; ff < yfade ; ff++ )
00300                FF(ii,ff,kk) = FF(ii,ny-1-ff,kk) = 0.0 ;
00301    }
00302 
00303    /*-- 06 Jun 2002: compute wtrimmed volume size --*/
00304 
00305    basis->xa = -1 ;  /* flag for no wtrim */
00306 
00307    if( wtrim ){
00308      int xa=-1,xb , ya,yb , za,zb ;
00309      MRI_autobbox( imww , &xa,&xb , &ya,&yb , &za,&zb ) ;
00310      if( xa >= 0 ){
00311        float nxyz = imww->nx * imww->ny * imww->nz ;
00312        float nttt = (xb-xa+1)*(yb-ya+1)*(zb-za+1) ;
00313        float trat = 100.0 * nttt / nxyz ;
00314 
00315        if( verbose )
00316          fprintf(stderr,"  wtrim: [%d..%d]x[%d..%d]x[%d..%d]"
00317                         " = %d voxels kept, out of %d (%.1f%%)\n" ,
00318                  xa,xb , ya,yb , za,zb , (int)nttt , (int)nxyz , trat ) ;
00319 
00320        /* keep trimming if saves at least 10% per volume */
00321 
00322        if( trat < 90.0 ){
00323          basis->xa = xa ; basis->xb = xb ;
00324          basis->ya = ya ; basis->yb = yb ;
00325          basis->za = za ; basis->zb = zb ;
00326 
00327          TRIM(imww) ;
00328        } else if( verbose ){
00329          fprintf(stderr,"  skipping use of trim - too little savings\n");
00330        }
00331      }
00332    }
00333 
00334    VRANG("weight",imww) ;
00335    if( verbose ){
00336      float *f=MRI_FLOAT_PTR(imww) , perc ;
00337      int ii , nxyz = imww->nvox , nzer=0 ;
00338      for( ii=0 ; ii < nxyz ; ii++ ) nzer += (f[ii] == 0.0) ;
00339      perc = (100.0*nzer)/nxyz ;
00340      fprintf(stderr,"  # zero weights=%d out of %d (%.1f%%)\n",nzer,nxyz,perc);
00341    }
00342 
00343    /*-- base image --*/
00344 
00345    INIT_IMARR( fitim ) ;             /* array of fitting images */
00346 
00347    if( DOTRIM ) bim = IMTRIM(cim) ;  /* a trimmed duplicate */
00348    else         bim = cim ;          /* base image */
00349    ADDTO_IMARR( fitim , bim ) ;
00350 
00351    THD_rota_method( regmode ) ;
00352 
00353 #ifndef MEGA
00354 #define MEGA (1024*1024)
00355 #endif
00356    if( verbose ) fprintf(stderr ,
00357                          "  mri_3dalign: using %d Mbytes of workspace\n" ,
00358                          10 * bim->nvox * bim->pixel_size / MEGA ) ;
00359 
00360    /*-- d/d(th1) image [angles in degrees here] --*/
00361 
00362    if( verbose ) fprintf(stderr,"  initializing d/d(th1)") ;
00363 
00364    delta = 2.0*delfac/( cim->nx + cim->ny + cim->nz ) ;
00365    if( verbose ) fprintf(stderr,"[delta=%g]",delta) ;
00366 
00367    pim = THD_rota3D( cim , ax1,delta , ax2,0.0 , ax3,0.0 ,
00368                      dcode , 0.0 , 0.0 , 0.0 ) ;
00369    if( verbose ) fprintf(stderr,":") ;
00370 
00371    mim = THD_rota3D( cim , ax1,-delta , ax2,0.0 , ax3,0.0 ,
00372                      dcode , 0.0 , 0.0 , 0.0 ) ;
00373    if( verbose ) fprintf(stderr,":") ;
00374 
00375    dim   = mri_new_conforming( cim , MRI_float ) ;
00376    delta = sinit * 0.5 * DFAC / delta ;
00377    dar   = MRI_FLOAT_PTR(dim) ; par = MRI_FLOAT_PTR(pim) ; mar = MRI_FLOAT_PTR(mim) ;
00378    for( ii=0 ; ii < dim->nvox ; ii++ )
00379       dar[ii] = delta * ( mar[ii] - par[ii] ) ;
00380    mri_free(pim) ; mri_free(mim) ;
00381    TRIM( dim ) ; ADDTO_IMARR( fitim , dim ) ;
00382    VRANG("d/d(th1)",dim) ;
00383 
00384    /*-- d/d(th2) image --*/
00385 
00386    if( verbose ) fprintf(stderr,"  initializing d/d(th2)") ;
00387 
00388    delta = 2.0*delfac/( cim->nx + cim->ny + cim->nz ) ;
00389    if( verbose ) fprintf(stderr,"[delta=%g]",delta) ;
00390 
00391    pim = THD_rota3D( cim , ax1,0.0 , ax2,delta , ax3,0.0 ,
00392                      dcode , 0.0 , 0.0 , 0.0 ) ;
00393    if( verbose ) fprintf(stderr,":") ;
00394 
00395    mim = THD_rota3D( cim , ax1,0.0 , ax2,-delta , ax3,0.0 ,
00396                      dcode , 0.0 , 0.0 , 0.0 ) ;
00397    if( verbose ) fprintf(stderr,":") ;
00398 
00399    dim   = mri_new_conforming( cim , MRI_float ) ;
00400    delta = sinit * 0.5 * DFAC / delta ;
00401    dar   = MRI_FLOAT_PTR(dim) ; par = MRI_FLOAT_PTR(pim) ; mar = MRI_FLOAT_PTR(mim) ;
00402    for( ii=0 ; ii < dim->nvox ; ii++ )
00403       dar[ii] = delta * ( mar[ii] - par[ii] ) ;
00404    mri_free(pim) ; mri_free(mim) ;
00405    TRIM( dim ) ; ADDTO_IMARR( fitim , dim ) ;
00406    VRANG("d/d(th2)",dim) ;
00407 
00408    /*-- d/d(th3) image --*/
00409 
00410    if( verbose ) fprintf(stderr,"  initializing d/d(th3)") ;
00411 
00412    delta = 2.0*delfac/( cim->nx + cim->ny + cim->nz ) ;
00413    if( verbose ) fprintf(stderr,"[delta=%g]",delta) ;
00414 
00415    pim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,delta ,
00416                      dcode , 0.0 , 0.0 , 0.0 ) ;
00417    if( verbose ) fprintf(stderr,":") ;
00418 
00419    mim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,-delta ,
00420                      dcode , 0.0 , 0.0 , 0.0 ) ;
00421    if( verbose ) fprintf(stderr,":") ;
00422 
00423    dim   = mri_new_conforming( cim , MRI_float ) ;
00424    delta = sinit * 0.5 * DFAC / delta ;
00425    dar   = MRI_FLOAT_PTR(dim) ; par = MRI_FLOAT_PTR(pim) ; mar = MRI_FLOAT_PTR(mim) ;
00426    for( ii=0 ; ii < dim->nvox ; ii++ )
00427       dar[ii] = delta * ( mar[ii] - par[ii] ) ;
00428    mri_free(pim) ; mri_free(mim) ;
00429    TRIM( dim ) ; ADDTO_IMARR( fitim , dim ) ;
00430    VRANG("d/d(th3)",dim) ;
00431 
00432    /*-- d/dx image --*/
00433 
00434    if( verbose ) fprintf(stderr,"  initializing d/dx") ;
00435 
00436    delta = delfac * dx ;
00437    if( verbose ) fprintf(stderr,"[delta=%g]",delta) ;
00438 
00439    pim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,0.0 ,
00440                      dcode , delta , 0.0 , 0.0 ) ;
00441    if( verbose ) fprintf(stderr,":") ;
00442 
00443    mim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,0.0 ,
00444                      dcode , -delta , 0.0 , 0.0 ) ;
00445    if( verbose ) fprintf(stderr,":") ;
00446 
00447    dim   = mri_new_conforming( cim , MRI_float ) ;
00448    delta = sinit * 0.5 / delta ;
00449    dar   = MRI_FLOAT_PTR(dim) ; par = MRI_FLOAT_PTR(pim) ; mar = MRI_FLOAT_PTR(mim) ;
00450    for( ii=0 ; ii < dim->nvox ; ii++ )
00451       dar[ii] = delta * ( mar[ii] - par[ii] ) ;
00452    mri_free(pim) ; mri_free(mim) ;
00453    TRIM( dim ) ; ADDTO_IMARR( fitim , dim ) ;
00454    VRANG("d/dx",dim) ;
00455 
00456    /*-- d/dy image --*/
00457 
00458    if( verbose ) fprintf(stderr,"  initializing d/dy") ;
00459 
00460    delta = delfac * dy ;
00461    if( verbose ) fprintf(stderr,"[delta=%g]",delta) ;
00462 
00463    pim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,0.0 ,
00464                      dcode , 0.0 , delta , 0.0 ) ;
00465    if( verbose ) fprintf(stderr,":") ;
00466 
00467    mim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,0.0 ,
00468                      dcode , 0.0 , -delta , 0.0 ) ;
00469    if( verbose ) fprintf(stderr,":") ;
00470 
00471    dim   = mri_new_conforming( cim , MRI_float ) ;
00472    delta = sinit * 0.5 / delta ;
00473    dar   = MRI_FLOAT_PTR(dim) ; par = MRI_FLOAT_PTR(pim) ; mar = MRI_FLOAT_PTR(mim) ;
00474    for( ii=0 ; ii < dim->nvox ; ii++ )
00475       dar[ii] = delta * ( mar[ii] - par[ii] ) ;
00476    mri_free(pim) ; mri_free(mim) ;
00477    TRIM( dim ) ; ADDTO_IMARR( fitim , dim ) ;
00478    VRANG("d/dy",dim) ;
00479 
00480    /*-- d/dz image --*/
00481 
00482    if( verbose ) fprintf(stderr,"  initializing d/dz") ;
00483 
00484    delta = delfac * dz ;
00485    if( verbose ) fprintf(stderr,"[delta=%g]",delta) ;
00486 
00487    pim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,0.0 ,
00488                      dcode , 0.0 , 0.0 , delta ) ;
00489    if( verbose ) fprintf(stderr,":") ;
00490 
00491    mim = THD_rota3D( cim , ax1,0.0 , ax2,0.0 , ax3,0.0 ,
00492                      dcode , 0.0 , 0.0 , -delta ) ;
00493    if( verbose ) fprintf(stderr,":") ;
00494 
00495    dim   = mri_new_conforming( cim , MRI_float ) ;
00496    delta = sinit * 0.5 / delta ;
00497    dar   = MRI_FLOAT_PTR(dim) ; par = MRI_FLOAT_PTR(pim) ; mar = MRI_FLOAT_PTR(mim) ;
00498    for( ii=0 ; ii < dim->nvox ; ii++ )
00499       dar[ii] = delta * ( mar[ii] - par[ii] ) ;
00500    mri_free(pim) ; mri_free(mim) ;
00501    TRIM( dim ) ; ADDTO_IMARR( fitim , dim ) ;
00502    VRANG("d/dz",dim) ;
00503 
00504    /*-- done with input copy, unless it is same as base for lsqfit --*/
00505 
00506    if( cim != bim ) mri_free(cim) ;
00507 
00508    /*-- initialize linear least squares --*/
00509 
00510    if( verbose ) fprintf(stderr,"  initializing least squares\n") ;
00511 
00512    chol_fitim = mri_startup_lsqfit( fitim , imww ) ;
00513 
00514    mri_free(imww) ;
00515 
00516    /*-- save stuff --*/
00517 
00518    basis->fitim      = fitim ;
00519    basis->chol_fitim = chol_fitim ;
00520 
00521    RETURN( basis );
00522 }

void mri_3dalign_wproccing int   
 

Definition at line 58 of file mri_3dalign.c.

References wproc.

00058 { wproc = ttt; } /* 06 Jun 2002 */

void mri_3dalign_wtrimming int   
 

Definition at line 56 of file mri_3dalign.c.

References wtrim.

Referenced by main(), and VL_command_line().

00056 { wtrim = ttt; } /* 06 Jun 2002 */

void MRI_autobbox MRI_IMAGE  ,
int *   ,
int *   ,
int *   ,
int *   ,
int *   ,
int *   
 

Definition at line 730 of file thd_automask.c.

References calloc, ENTRY, fim, free, MRI_IMAGE::kind, mmm, MRI_FLOAT_PTR, mri_free(), mri_to_float(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, nz, MRI_IMAGE::nz, THD_mask_clust(), and THD_mask_erode().

Referenced by mri_3dalign_setup(), and THD_autobbox().

00732 {
00733    MRI_IMAGE *fim ;
00734    float *mar ;
00735    byte *mmm = NULL ;
00736    int nvox , ii,jj,kk , nmm , nx,ny,nz,nxy ;
00737 
00738 ENTRY("MRI_autobbox") ;
00739 
00740    /* find largest component as in first part of THD_automask() */
00741 
00742    if( qim->kind != MRI_float ) fim = mri_to_float(qim) ;
00743    else                         fim = qim ;
00744 
00745    nvox = fim->nvox ;
00746    mar  = MRI_FLOAT_PTR(fim) ;
00747    mmm  = (byte *) calloc( sizeof(byte) , nvox ) ;
00748    for( nmm=ii=0 ; ii < nvox ; ii++ )
00749      if( mar[ii] != 0.0 ){ mmm[ii] = 1; nmm++; }
00750 
00751    if( fim != qim ) mri_free(fim) ;
00752 
00753    if( nmm == 0 ){ free(mmm); EXRETURN; }
00754 
00755    nx = qim->nx; ny = qim->ny; nz = qim->nz; nxy = nx*ny;
00756 
00757    THD_mask_clust( nx,ny,nz, mmm ) ;
00758    THD_mask_erode( nx,ny,nz, mmm ) ;
00759    THD_mask_clust( nx,ny,nz, mmm ) ;
00760 
00761    /* For each plane direction,
00762       find the first and last index that have nonzero voxels in that plane */
00763 
00764    if( xm != NULL ){
00765      for( ii=0 ; ii < nx ; ii++ )
00766        for( kk=0 ; kk < nz ; kk++ )
00767          for( jj=0 ; jj < ny ; jj++ )
00768            if( mmm[ii+jj*nx+kk*nxy] ) goto CP5 ;
00769      CP5: *xm = ii ;
00770    }
00771 
00772    if( xp != NULL ){
00773      for( ii=nx-1 ; ii >= 0 ; ii-- )
00774        for( kk=0 ; kk < nz ; kk++ )
00775          for( jj=0 ; jj < ny ; jj++ )
00776            if( mmm[ii+jj*nx+kk*nxy] ) goto CP6 ;
00777      CP6: *xp = ii ;
00778    }
00779 
00780    if( ym != NULL ){
00781      for( jj=0 ; jj < ny ; jj++ )
00782        for( kk=0 ; kk < nz ; kk++ )
00783          for( ii=0 ; ii < nx ; ii++ )
00784            if( mmm[ii+jj*nx+kk*nxy] ) goto CP3 ;
00785      CP3: *ym = jj ;
00786    }
00787 
00788    if( yp != NULL ){
00789      for( jj=ny-1 ; jj >= 0 ; jj-- )
00790        for( kk=0 ; kk < nz ; kk++ )
00791          for( ii=0 ; ii < nx ; ii++ )
00792            if( mmm[ii+jj*nx+kk*nxy] ) goto CP4 ;
00793      CP4: *yp = jj ;
00794    }
00795 
00796    if( zm != NULL ){
00797      for( kk=0 ; kk < nz ; kk++ )
00798        for( jj=0 ; jj < ny ; jj++ )
00799          for( ii=0 ; ii < nx ; ii++ )
00800            if( mmm[ii+jj*nx+kk*nxy] ) goto CP1 ;
00801      CP1: *zm = kk ;
00802    }
00803 
00804    if( zp != NULL ){
00805      for( kk=nz-1 ; kk >= 0 ; kk-- )
00806        for( jj=0 ; jj < ny ; jj++ )
00807          for( ii=0 ; ii < nx ; ii++ )
00808            if( mmm[ii+jj*nx+kk*nxy] ) goto CP2 ;
00809      CP2: *zp = kk ;
00810    }
00811 
00812    free(mmm) ; EXRETURN ;
00813 }

byte* mri_automask_image MRI_IMAGE   im
 

Make a byte mask from an image (3D). Adapted from THD_automask() to make it possible to do this on an image directly. -----------------------------------------------------------------------

Definition at line 92 of file thd_automask.c.

References AFNI_yesenv(), calloc, dall, ENTRY, exterior_clip, ININFO_message(), MRI_IMAGE::kind, mask_count(), MAX, mmm, MRI_FLOAT_PTR, mri_free(), mri_to_float(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, nz, MRI_IMAGE::nz, RETURN, THD_cliplevel(), THD_mask_clip_neighbors(), THD_mask_clust(), THD_mask_erode(), THD_mask_fillin_completely(), THD_mask_fillin_once(), THD_peel_mask(), and verb.

Referenced by main(), mri_automask_imarr(), read_input_data(), and THD_automask().

00093 {
00094    float clip_val , *mar ;
00095    byte *mmm = NULL ;
00096    int nvox , ii,jj , nmm , nx,ny,nz ;
00097    MRI_IMAGE *medim ;
00098 
00099 ENTRY("mri_automask_image") ;
00100 
00101    if( im == NULL ) return NULL ;
00102 
00103    if( im->kind != MRI_float ) medim = mri_to_float(im) ;
00104    else                        medim = im ;
00105 
00106    /* find clip value to excise small stuff */
00107 
00108    clip_val = THD_cliplevel(medim,0.5) ;
00109 
00110    if( verb ) ININFO_message("Clip level = %f\n",clip_val) ;
00111 
00112    /* create mask of values above clip value */
00113 
00114    nvox = medim->nvox ;
00115    mar  = MRI_FLOAT_PTR(medim) ;
00116    mmm  = (byte *) calloc( sizeof(byte), nvox ) ;
00117    for( nmm=ii=0 ; ii < nvox ; ii++ )
00118      if( mar[ii] >= clip_val ){ mmm[ii] = 1; nmm++; }
00119 
00120    if( AFNI_yesenv("TOPCLIP") ){
00121      float tclip = 3.1*clip_val ;
00122      if( verb ) ININFO_message("Top clip = %f\n",tclip) ;
00123      for( ii=0 ; ii < nvox ; ii++ )
00124        if( mar[ii] > tclip ) mmm[ii] = 0 ;
00125      for( nmm=ii=0 ; ii < nvox ; ii++ ) if( mmm[ii] ) nmm++ ;
00126    }
00127 
00128    if( verb ) ININFO_message("Number voxels above clip level = %d\n",nmm) ;
00129    if( im != medim && (!exterior_clip || nmm==0) ){ mri_free(medim); medim=NULL; }
00130    if( nmm == 0 ) RETURN(mmm) ;  /* should not happen */
00131 
00132    /*-- 10 Apr 2002: only keep the largest connected component --*/
00133 
00134    nx = im->nx ; ny = im->ny ; nz = im->nz ;
00135    dall = (nx*ny*nz)/128 ;  /* allocation delta for clustering */
00136 
00137    if( verb ) ININFO_message("Clustering voxels above clip level ...\n") ;
00138    THD_mask_clust( nx,ny,nz, mmm ) ;
00139 
00140    /* 18 Apr 2002: now erode the resulting volume
00141                    (to break off any thinly attached pieces) */
00142 
00143    THD_mask_erode( nx,ny,nz, mmm ) ;
00144 
00145    /* now recluster it, and again keep only the largest survivor */
00146 
00147    THD_mask_clust( nx,ny,nz, mmm ) ;
00148 
00149 #ifdef USE_FILLIN
00150    /* 19 Apr 2002: fill in small holes */
00151 
00152    jj = ii = THD_mask_fillin_once( nx,ny,nz , mmm , 1 ) ;
00153    if( ii > 0 ){
00154      jj += ii = THD_mask_fillin_once( nx,ny,nz , mmm , 1 ) ;
00155      if( ii > 0 ){
00156        jj += ii = THD_mask_fillin_once( nx,ny,nz , mmm , 1 ) ;
00157      }
00158    }
00159    if( jj > 0 && verb )
00160     ININFO_message("Filled   %d voxels in small holes; now have %d voxels\n",
00161             jj , mask_count(nvox,mmm) ) ;
00162 
00163    if( AFNI_yesenv("PEEL") ){
00164      jj = THD_peel_mask( nx,ny,nz , mmm , 7 ) ;
00165      if( jj > 0 ){
00166        ININFO_message("Peeled %d voxels from surface\n",jj) ;
00167        THD_mask_erode( nx,ny,nz, mmm ) ;
00168        THD_mask_clust( nx,ny,nz, mmm ) ;
00169      }
00170    }
00171 
00172    nmm = 1 ;
00173    jj  = rint(0.016*nx) ; nmm = MAX(nmm,jj) ;
00174    jj  = rint(0.016*ny) ; nmm = MAX(nmm,jj) ;
00175    jj  = rint(0.016*nz) ; nmm = MAX(nmm,jj) ;
00176 
00177    if( nmm > 1 || jj > 0 ){
00178      for( jj=0,ii=2 ; ii < nmm ; ii++ )
00179        jj += THD_mask_fillin_once( nx,ny,nz , mmm , ii ) ;
00180      jj += THD_mask_fillin_completely( nx,ny,nz, mmm , nmm ) ;
00181      if( jj > 0 && verb )
00182       ININFO_message("Filled   %d voxels in large holes; now have %d voxels\n",
00183               jj , mask_count(nvox,mmm) ) ;
00184    }
00185 
00186    THD_mask_erode( nx,ny,nz, mmm ) ;
00187    THD_mask_clust( nx,ny,nz, mmm ) ;
00188 #endif
00189 
00190    /* 28 May 2002:
00191       invert the mask, then find the largest cluster of 1's;
00192       this will be the outside of the brain;
00193       put this back into the mask, then invert again;
00194       the effect will be to fill any holes left inside the brain */
00195 
00196    for( ii=0 ; ii < nvox ; ii++ ) mmm[ii] = !mmm[ii] ;
00197 
00198    if( verb ) ININFO_message("Clustering non-brain voxels ...\n") ;
00199    THD_mask_clust( nx,ny,nz, mmm ) ;
00200 
00201    /* mask is now 1 for non-brain voxels;
00202       if we want to clip off voxels neighboring the non-brain
00203       mask AND whose values are below clip_val, do so now     */
00204 
00205    if( exterior_clip ){
00206      float tclip ;
00207      tclip = AFNI_yesenv("TOPCLIP") ? 3.1*clip_val : 9999.9*clip_val ;;
00208      jj = THD_mask_clip_neighbors( nx,ny,nz , mmm , clip_val,tclip,mar ) ;
00209      if( im != medim ) mri_free(medim) ;
00210      if( jj > 0 && verb )
00211        ININFO_message("Removed  %d exterior voxels below clip level\n",jj);
00212    } else {
00213      jj = 0 ;
00214    }
00215 
00216    /* and re-invert mask to get brain voxels */
00217 
00218    for( ii=0 ; ii < nvox ; ii++ ) mmm[ii] = !mmm[ii] ;
00219    if( verb ) ININFO_message("Mask now has %d voxels\n",mask_count(nvox,mmm)) ;
00220 
00221    if( exterior_clip && jj > 0 ){
00222      THD_mask_erode( nx,ny,nz, mmm ) ;
00223      THD_mask_clust( nx,ny,nz, mmm ) ;
00224    }
00225 
00226    RETURN(mmm) ;
00227 }

byte* mri_automask_imarr MRI_IMARR   imar
 

Make a byte mask from the average of an array of 3D images. We assume that they all have the same (nx,ny,nz) dimensions. -----------------------------------------------------------------------

Definition at line 52 of file thd_automask.c.

References ENTRY, IMARR_COUNT, IMARR_SUBIMAGE, MRI_IMAGE::kind, mmm, mri_automask_image(), MRI_FLOAT_PTR, mri_free(), mri_new_conforming, mri_to_float(), MRI_IMAGE::nvox, and RETURN.

00053 {
00054    MRI_IMAGE *avim , *tim , *qim ;
00055    byte *mmm ;
00056    int ii , jj , nvox,nim ;
00057    float fac , *avar , *qar ;
00058 
00059 ENTRY("mri_automask_imarr") ;
00060 
00061    if( imar == NULL || IMARR_COUNT(imar) < 1 ) RETURN(NULL) ;
00062 
00063    nim = IMARR_COUNT(imar) ;
00064    if( nim == 1 ){
00065      mmm = mri_automask_image( IMARR_SUBIMAGE(imar,0) ) ;
00066      RETURN(mmm) ;
00067    }
00068 
00069    avim = mri_new_conforming( IMARR_SUBIMAGE(imar,0) , MRI_float ) ;
00070    avar = MRI_FLOAT_PTR(avim) ;
00071    nvox = avim->nvox ;
00072    for( jj=0 ; jj < nim ; jj++ ){
00073      tim = IMARR_SUBIMAGE(imar,jj) ;
00074      if( tim->kind != MRI_float ) qim = mri_to_float(tim) ;
00075      else                         qim = tim ;
00076      qar = MRI_FLOAT_PTR(qim) ;
00077      for( ii=0 ; ii < nvox ; ii++ ) avar[ii] += qar[ii] ;
00078      if( qim != tim ) mri_free(qim) ;
00079    }
00080    fac = 1.0f / (float)nim ;
00081    for( ii=0 ; ii < nvox ; ii++ ) avar[ii] *= fac ;
00082    mmm = mri_automask_image( avim ) ;
00083    mri_free(avim) ;
00084    RETURN(mmm) ;
00085 }

MRI_IMAGE* mri_brainormalize MRI_IMAGE  ,
int   ,
int   ,
int   ,
MRI_IMAGE **   ,
MRI_IMAGE **   
 

Definition at line 1106 of file thd_brainormalize.c.

References abs, AFNI_noenv(), AFNI_yesenv(), ai, aj, ak, bi, bj, bk, calloc, clipvec::clip_000, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, free, get_octant_clips(), ijk_invwarp(), ijkwarp(), MRI_IMAGE::kind, LAST_ORIENT_TYPE, malloc, mask_count(), MRI_BYTE_PTR, MRI_COPY_AUX, MRI_CUBIC, mri_flip3D(), mri_free(), mri_maxabs(), mri_new_conforming, MRI_NN, mri_short2mask(), MRI_SHORT_PTR, mri_to_short(), mri_warp3D(), mri_warp3D_method(), MRI_IMAGE::nx, MRI_IMAGE::ny, nz, MRI_IMAGE::nz, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, pointclip(), RETURN, SHORTIZE, thd_bn_dxyz, thd_bn_nx, thd_bn_ny, thd_bn_nz, THD_BN_XCM, THD_BN_XORG, THD_BN_YCM, THD_BN_YORG, THD_BN_ZCM, THD_BN_ZHEIGHT, THD_BN_ZORG, THD_mask_clust(), THD_mask_dilate(), THD_mask_distize(), THD_mask_erode(), THD_mask_fillin_once(), verb, MRI_IMAGE::xo, MRI_IMAGE::yo, z1, and MRI_IMAGE::zo.

Referenced by main().

01107 {
01108    MRI_IMAGE *sim , *tim , *bim ;
01109    short *sar , sval ;
01110    int ii,jj,kk,ijk,ktop,kbot , nx,ny,nz,nxy,nxyz ;
01111    float val , icm,jcm,kcm,sum , dx,dy,dz ;
01112    byte *mask , *bar ;
01113    float sim_dx, sim_dy, sim_dz, sim_xo, sim_yo, sim_zo;
01114    int sim_nx, sim_ny, sim_nz;
01115    int *zcount , *hist,*gist , z1,z2,z3 ;
01116    MRI_IMAGE *imout_orig = NULL;
01117    
01118 ENTRY("mri_brainormalize") ;
01119 
01120    if( im == NULL || xxor < 0 || xxor > LAST_ORIENT_TYPE ||
01121                      yyor < 0 || yyor > LAST_ORIENT_TYPE ||
01122                      zzor < 0 || zzor > LAST_ORIENT_TYPE   ) RETURN(NULL) ;
01123 
01124    if( im->nx < 16 || im->ny < 16 || im->nz < 16 ) RETURN(NULL) ;
01125 
01126    val = mri_maxabs(im) ; if( val <= 0.0 ) RETURN(NULL) ;
01127 
01128    /* make a short copy */
01129 
01130    if( verb ) fprintf(stderr,"++mri_brainormalize: copying input\n") ;
01131 
01132    if( im->kind == MRI_short || im->kind == MRI_byte || im->kind == MRI_rgb )
01133      tim = mri_to_short( 1.0 , im ) ;
01134    else
01135      tim = mri_to_short( 32767.0/val , im ) ;
01136 
01137    /* flip to RAI orientation */
01138 
01139    ii = jj = kk = 0 ;
01140    switch( xxor ){
01141      case ORI_R2L_TYPE: ii =  1 ; break ;
01142      case ORI_L2R_TYPE: ii = -1 ; break ;
01143      case ORI_P2A_TYPE: jj = -1 ; break ;
01144      case ORI_A2P_TYPE: jj =  1 ; break ;
01145      case ORI_I2S_TYPE: kk =  1 ; break ;
01146      case ORI_S2I_TYPE: kk = -1 ; break ;
01147    }
01148    switch( yyor ){
01149      case ORI_R2L_TYPE: ii =  2 ; break ;
01150      case ORI_L2R_TYPE: ii = -2 ; break ;
01151      case ORI_P2A_TYPE: jj = -2 ; break ;
01152      case ORI_A2P_TYPE: jj =  2 ; break ;
01153      case ORI_I2S_TYPE: kk =  2 ; break ;
01154      case ORI_S2I_TYPE: kk = -2 ; break ;
01155    }
01156    switch( zzor ){
01157      case ORI_R2L_TYPE: ii =  3 ; break ;
01158      case ORI_L2R_TYPE: ii = -3 ; break ;
01159      case ORI_P2A_TYPE: jj = -3 ; break ;
01160      case ORI_A2P_TYPE: jj =  3 ; break ;
01161      case ORI_I2S_TYPE: kk =  3 ; break ;
01162      case ORI_S2I_TYPE: kk = -3 ; break ;
01163    }
01164 
01165    if( ii==1 && jj==2 && kk==3 ){      /* no flip needed */
01166      sim = tim ;
01167    } else {                            /* flipization */
01168      if( verb )
01169        fprintf(stderr,"++mri_brainormalize: flipping to RAI orientation\n") ;
01170      sim = mri_flip3D( ii,jj,kk , tim ) ;
01171      mri_free(tim) ;
01172      if( sim == NULL ) RETURN(NULL) ;  /* bad orientation codes? */
01173    }
01174 
01175    sar = MRI_SHORT_PTR(sim) ;
01176    if( sar == NULL ){ mri_free(sim); RETURN(NULL); }  /* bad image? */
01177 
01178    /* make a binary mask */
01179 
01180    nx = sim->nx ; ny = sim->ny ; nz = sim->nz ; nxy = nx*ny ; nxyz = nxy*nz ;
01181    dx = fabs(sim->dx) ; if( dx == 0.0 ) dx = 1.0 ;
01182    dy = fabs(sim->dy) ; if( dy == 0.0 ) dy = 1.0 ;
01183    dz = fabs(sim->dz) ; if( dz == 0.0 ) dz = 1.0 ;
01184       
01185    /* save some info to create an output image with the same number of slices as original image*/
01186    sim_dx = sim->dx; sim_dy = sim->dy; sim_dz = sim->dz;
01187    sim_xo = 0.0; sim_yo = 0.0; sim_zo = 0.0;  /* origins are added after this function returns.*/
01188    sim_nx = sim->nx; sim_ny = sim->ny; sim_nz = sim->nz; 
01189    
01190    if( verb ) fprintf(stderr,"++mri_brainormalize: making mask\n") ;
01191    mask = mri_short2mask( sim ) ;
01192 
01193    if( mask == NULL ){ mri_free(sim); RETURN(NULL); }
01194 
01195    /* fill in any isolated holes in mask */
01196 
01197    (void) THD_mask_fillin_once( nx,ny,nz , mask , 2 ) ;  /* thd_automask.c */
01198           THD_mask_dilate     ( nx,ny,nz , mask , 5 ) ;
01199           THD_mask_dilate     ( nx,ny,nz , mask , 5 ) ;
01200 
01201    kk = mask_count(nxyz,mask) ;
01202    if( verb )
01203      fprintf(stderr,"++mri_brainormalize: filled in mask now has %d voxels\n",kk) ;
01204 
01205    if( kk <= 999 ){ free((void *)mask); mri_free(sim); RETURN(NULL); }
01206 
01207    /* descending from Superior:
01208         count biggest blob in each slice
01209         find Superiormost location that has 3
01210           slices in a row with "a lot" of stuff
01211         zero out all stuff out above that slice */
01212 
01213    zcount = (int *)  malloc( sizeof(int) *nz  ) ;  /* slice counts */
01214    for( kk=nz-1 ; kk >= 0 ; kk-- ){
01215      zcount[kk] = mask_count( nxy , mask+kk*nxy ) ;
01216    }
01217 
01218 #if 0
01219    if( verb ){
01220      fprintf(stderr,"++mri_brainormalize: zcount from top slice #%d\n",nz-1) ;
01221      for( kk=nz-1 ; kk >= 0 ; kk-- ){
01222        fprintf(stderr," %.3f",((double)(zcount[kk]))/((double)nxy) ) ;
01223        if( (nz-kk)%10 == 0 && kk > 0 ) fprintf(stderr,"\n") ;
01224      }
01225      fprintf(stderr,"\n") ;
01226    }
01227 #endif
01228 
01229    /* search down for topmost slice that meets the criterion */
01230 
01231    z1 = (int)(0.010*nxy) ;
01232    z2 = (int)(0.015*nxy) ;
01233    z3 = (int)(0.020*nxy) ;
01234    for( kk=nz-1 ; kk > 2 ; kk-- )
01235      if( zcount[kk] >= z1 && zcount[kk-1] >= z2 && zcount[kk-2] >= z3 ) break ;
01236 
01237    free((void *)zcount) ;
01238    if( kk <= 2 ){ free((void *)mask); mri_free(sim); RETURN(NULL); }
01239 
01240    /* zero out all above the slice we just found */
01241 
01242    ktop = kk ;
01243    if( ktop < nz-1 ){
01244      if( verb )
01245        fprintf(stderr,"++mri_brainormalize: top clip above slice %d\n",ktop) ;
01246      memset( mask+(ktop+1)*nxy , 0 , nxy*(nz-1-ktop)*sizeof(byte) ) ;
01247    }
01248 
01249    /* find slice index THD_BN_ZHEIGHT mm below that top slice */
01250 
01251    jj = (int)( ktop-THD_BN_ZHEIGHT/dz ) ;
01252    if( jj >= 0 ){
01253      if( verb )
01254        fprintf(stderr,"++mri_brainormalize: bot clip below slice %d\n",jj) ;
01255      memset( mask , 0 , nxy*(jj+1)*sizeof(byte) ) ;
01256    }
01257 
01258    kk = mask_count(nxyz,mask) ;
01259    if( kk <= 999 ){ free((void *)mask); mri_free(sim); RETURN(NULL); }
01260 
01261    /* apply mask to image (will also remove any negative values) */
01262 
01263    if( verb )
01264      fprintf(stderr,"++mri_brainormalize: applying mask to image; %d voxels\n",kk) ;
01265    for( ii=0 ; ii < nxyz ; ii++ ) if( !mask[ii] ) sar[ii] = 0 ;
01266 
01267    free((void *)mask) ;  /* done with this mask */
01268 
01269    /* compute CM of masked image (indexes, not mm) */
01270 
01271    icm = jcm = kcm = sum = 0.0 ;
01272 #ifndef THD_BN_CMTOP
01273    kbot = 0 ;
01274    ktop = nz-1 ;
01275 #else
01276    kbot = (int)rint( ktop-110.0/dz ); if( kbot < 0 ) kbot = 0;
01277 #endif
01278    for( ijk=kbot*nxy,kk=kbot ; kk <= ktop ; kk++ ){
01279     for( jj=0 ; jj < ny ; jj++ ){
01280      for( ii=0 ; ii < nx ; ii++,ijk++ ){
01281        val = (float)sar[ijk] ;
01282        sum += val ;
01283        icm += val * ii ;
01284        jcm += val * jj ;
01285        kcm += val * kk ;
01286    }}}
01287    if( sum == 0.0 ){ mri_free(sim); RETURN(NULL); }  /* huh? */
01288 
01289    ai = thd_bn_dxyz/dx ; bi = icm/sum - ai*(THD_BN_XCM-THD_BN_XORG)/thd_bn_dxyz ;
01290    aj = thd_bn_dxyz/dy ; bj = jcm/sum - aj*(THD_BN_YCM-THD_BN_YORG)/thd_bn_dxyz ;
01291    ak = thd_bn_dxyz/dz ; bk = kcm/sum - ak*(THD_BN_ZCM-THD_BN_ZORG)/thd_bn_dxyz ;
01292 
01293    if( verb ) fprintf(stderr,"++mri_brainormalize: warping to standard grid\n a = [%f %f %f], b = [%f %f %f]\n", ai, aj, ak, bi, bj, bk) ;
01294 
01295    mri_warp3D_method( MRI_CUBIC ) ;
01296    tim = mri_warp3D( sim , thd_bn_nx,thd_bn_ny,thd_bn_nz , ijkwarp ) ;
01297    mri_free(sim) ;
01298 
01299    tim->dx = tim->dy = tim->dz = thd_bn_dxyz ;
01300    tim->xo = THD_BN_XORG ;
01301    tim->yo = THD_BN_YORG ;
01302    tim->zo = THD_BN_ZORG ;
01303    
01304    nx = tim->nx ; ny = tim->ny ; nz = tim->nz ; nxy = nx*ny ; nxyz = nxy*nz ;
01305    sar = MRI_SHORT_PTR(tim) ;
01306 
01307    /*-- rescale to partially uniformize --*/
01308 
01309    { clipvec bvec ; float bval , sv ;
01310      bvec = get_octant_clips( tim , 0.40f ) ;
01311      if( bvec.clip_000 > 0.0f ){
01312        for( ijk=kk=0 ; kk < nz ; kk++ ){
01313         for( jj=0 ; jj < ny ; jj++ ){
01314          for( ii=0 ; ii < nx ; ii++,ijk++ ){
01315            bval = pointclip( ii,jj,kk , &bvec ) ; /* cliplevel here */
01316            sv   = 1000.0f * sar[ijk] / bval ;
01317            sar[ijk] = SHORTIZE(sv) ;
01318          }
01319      }}}
01320    }
01321 
01322    /*-- build another mask now --*/
01323    if( !AFNI_noenv("REMASK") ){
01324      int sbot,stop , nwid , cbot,ctop , ibot,itop ;
01325      float dsum , ws , *wt ;
01326      int pval[128] , wval[128] , npk , tval , nmask,nhalf ;
01327      float pdif ;
01328      short mbot,mtop ;
01329 
01330      /* build histogram */
01331 
01332      hist = (int *) calloc(sizeof(int),32768) ;
01333      gist = (int *) calloc(sizeof(int),32768) ;
01334 
01335      memset( hist , 0 , sizeof(int)*32768 ) ;
01336      for( ii=0 ; ii < nxyz ; ii++ ) hist[sar[ii]]++ ;
01337      for( sbot=1 ; sbot < 32768 && hist[sbot]==0 ; sbot++ ) ; /* nada */
01338      if( sbot == 32768 ) goto Remask_Done ;
01339      for( stop=32768-1 ; stop > sbot && hist[stop]==0 ; stop-- ) ; /* nada */
01340      if( stop == sbot ) goto Remask_Done ;
01341 
01342      /* find median */
01343      
01344      nmask = 0 ;
01345      for( ii=sbot ; ii <= stop ; ii++ ) nmask += hist[ii] ;
01346      nhalf = nmask / 2 ; nmask = 0 ;
01347      for( ii=sbot ; ii <= stop && nmask < nhalf ; ii++ ) nmask += hist[ii] ;
01348      cbot = 0.40 * ii ;
01349      ctop = 1.60 * ii ;
01350 
01351 #if 0
01352      /* smooth histogram */
01353 
01354      nwid = rint(0.10*cbot) ;
01355 
01356      if( nwid <= 0 ){
01357        memcpy( gist , hist , sizeof(int)*32768 ) ;
01358      } else {
01359        ws = 0.0f ;
01360        wt = (float *)malloc(sizeof(float)*(2*nwid+1)) ;
01361        for( ii=0 ; ii <= 2*nwid ; ii++ ){
01362          wt[ii] = nwid-abs(nwid-ii) + 0.5f ;
01363          ws += wt[ii] ;
01364        }
01365        for( ii=0 ; ii <= 2*nwid ; ii++ ) wt[ii] /= ws ;
01366        for( jj=cbot ; jj <= ctop ; jj++ ){
01367          ibot = jj-nwid ; if( ibot < sbot ) ibot = sbot ;
01368          itop = jj+nwid ; if( itop > stop ) itop = stop ;
01369          ws = 0.0 ;
01370          for( ii=ibot ; ii <= itop ; ii++ )
01371            ws += wt[nwid-jj+ii] * hist[ii] ;
01372          gist[jj] = rint(ws) ;
01373        }
01374        free(wt) ;
01375      }
01376 
01377      /* scan for peaks */
01378 
01379      npk = 0 ;
01380      for( ii=cbot+2 ; ii <= ctop-2 ; ii++ ){
01381        if( gist[ii] > gist[ii-1] &&
01382            gist[ii] > gist[ii-2] &&
01383            gist[ii] > gist[ii+1] &&
01384            gist[ii] > gist[ii+2]   ){
01385              pval[npk]=ii; wval[npk++] = gist[ii];
01386            }
01387 
01388        else if( gist[ii] == gist[ii+1] &&   /* very special case */
01389                 gist[ii] >  gist[ii-1] &&
01390                 gist[ii] >  gist[ii-2] &&
01391                 gist[ii] >  gist[ii+2]   ){
01392                   pval[npk]=ii+0.5; wval[npk++] = gist[ii];
01393                 }
01394 
01395        else if( gist[ii] == gist[ii+1] &&   /* super special case */
01396                 gist[ii] == gist[ii-1] &&
01397                 gist[ii] >  gist[ii-2] &&
01398                 gist[ii] >  gist[ii+2]   ){
01399                   pval[npk]=ii; wval[npk++] = gist[ii];
01400                 }
01401      }
01402 
01403      if( npk > 2 ){  /* find largest two peaks and keep only them */
01404        float pval_top, pval_2nd, wval_top, wval_2nd , www; int iii,itop ;
01405        www = wval[0] ; iii = 0 ;
01406        for( ii=1 ; ii < npk ; ii++ ){
01407          if( wval[ii] > www ){ www = wval[ii] ; iii = ii ; }
01408        }
01409        pval_top = pval[iii] ; wval_top = www ; itop = iii ;
01410        www = -1 ; iii = -1 ;
01411        for( ii=0 ; ii < npk ; ii++ ){
01412          if( ii != itop && wval[ii] > www ){ www = wval[ii] ; iii = ii ; }
01413        }
01414        pval_2nd = pval[iii] ; wval_2nd = www ;
01415 
01416        /* make sure peaks are increasing in pval */
01417 
01418        if( pval_top < pval_2nd ){
01419          pval[0] = pval_top ; wval[0] = wval_top ;
01420          pval[1] = pval_2nd ; wval[1] = wval_2nd ;
01421        } else {
01422          pval[0] = pval_2nd ; wval[0] = wval_2nd ;
01423          pval[1] = pval_top ; wval[1] = wval_top ;
01424        }
01425        npk = 2 ;
01426      }
01427 
01428      if( npk == 2 ){
01429        jj = gist[pval[0]] ; tval = pval[0] ;
01430        for( ii=pval[0]+1 ; ii < pval[1] ; ii++ ){
01431          if( gist[ii] < jj ){ tval = ii ; jj = gist[ii] ; }
01432        }
01433 
01434        pdif = 1.5f * (tval-pval[0]) ;
01435        if( pdif < pval[1]-pval[0] ) pdif = pval[1]-pval[0] ;
01436        mbot = (short)(pval[0]-pdif) ;
01437        if( mbot < cbot ) mbot = cbot ;
01438 
01439        pdif = 1.5f * (pval[1]-tval) ;
01440        if( pdif < pval[1]-pval[0] ) pdif = pval[1]-pval[0] ;
01441        mtop = (short)(pval[1]+pdif) ;
01442        if( mtop > ctop ) mtop = ctop ;
01443      } else {
01444        mbot = cbot ; mtop = ctop ;
01445      }
01446      mtop = stop+1 ;  /* effectively, no threshold here */
01447 #endif
01448 
01449      mbot = cbot ; mtop = 32767 ;
01450 
01451      if( verb )
01452       fprintf(stderr,"++mri_brainormalize: masking standard image %d..%d\n",mbot,mtop) ;
01453 
01454      mask = (byte *) malloc( sizeof(byte)*nxyz ) ;
01455      for( ii=0 ; ii < nxyz ; ii++ )
01456        mask[ii] = (sar[ii] > mbot) && (sar[ii] < mtop) ;
01457 
01458      THD_mask_erode( nx,ny,nz, mask ) ;
01459      THD_mask_clust( nx,ny,nz, mask ) ;
01460      for( ii=0 ; ii < nxyz ; ii++ ) mask[ii] = !mask[ii] ;
01461      THD_mask_clust( nx,ny,nz, mask ) ;
01462      for( ii=0 ; ii < nxyz ; ii++ ) mask[ii] = !mask[ii] ;
01463 
01464      for( ii=0 ; ii < nxyz ; ii++ ) if( !mask[ii] ) sar[ii] = 0 ;
01465      free((void *)mask) ;
01466 
01467    Remask_Done:
01468      free((void *)hist) ; free((void *)gist) ;
01469 
01470    }
01471 #if 0
01472    else
01473 #endif
01474    {
01475      /*-- clip top 1% of values that have survived --*/
01476 
01477      hist = (int *) calloc(sizeof(int),32768) ;
01478      for( ii=0 ; ii < nxyz ; ii++ ) hist[sar[ii]]++ ;
01479      for( ii=kk=0 ; ii < 32767 ; ii++ ) kk += hist[ii] ;
01480      kk = (int)(0.01*kk) ; ktop = 0 ;
01481      for( jj=0,ii=32767 ; ii > 0 && jj < kk ; ii-- ){
01482        jj += hist[ii] ; if( hist[ii] > 0 && ktop == 0 ) ktop = ii ;
01483      }
01484      jj = ii ;
01485      if( verb ) fprintf(stderr," + 99%% clipping at %d (from %d)\n",jj,ktop) ;
01486      for( ii=0 ; ii < nxyz ; ii++ ) if( sar[ii] > jj ) sar[ii] = jj ;
01487 
01488      free((void *)hist) ;
01489    }
01490 
01491    /* distize? */
01492 
01493    if( AFNI_yesenv("DISTIZE") ){
01494      byte *ccc = (byte *)calloc(sizeof(byte),nxyz);
01495      short *ddd ;
01496      int kbot=(int)rint(0.45*nz) , ktop=(int)rint(0.65*nz) ,
01497          jbot=(int)rint(0.30*ny) , jtop=(int)rint(0.70*ny) ,
01498          ibot=(int)rint(0.30*nx) , itop=(int)rint(0.70*nx)  ;
01499 
01500      mask = (byte *)malloc( sizeof(byte)*nxyz ) ;
01501      for( ii=0 ; ii < nxyz ; ii++ ) mask[ii] = (sar[ii] > 0) ;
01502      for( kk=kbot ; kk <= ktop ; kk++ ){
01503       for( jj=jbot ; jj <= jtop ; jj++ ){
01504        for( ii=ibot ; ii <= itop ; ii++ ){
01505          ijk = ii + jj*nx + kk*nxy ;
01506          ccc[ijk] = mask[ijk] ;
01507      }}}
01508      if( verb ) fprintf(stderr," + distizing\n") ;
01509      ddd = THD_mask_distize( nx,ny,nz , mask , ccc ) ;
01510      if( ddd != NULL ){
01511        int id,jd,kd , ijk , dijk ; float ff ;
01512        for( ijk=0 ; ijk < nxyz ; ijk++ ){
01513          if( ddd[ijk] > 0 ){
01514            ii = ijk % nx ; jj = (ijk%nxy)/nx ; kk = ijk / nxy ;
01515                 if( ii < ibot ) id = ibot-ii ;
01516            else if( ii > itop ) id = ii-itop ; else id = 0 ;
01517                 if( jj < jbot ) jd = jbot-jj ;
01518            else if( jj > jtop ) jd = jj-jtop ; else jd = 0 ;
01519                 if( kk < kbot ) kd = kbot-kk ;
01520            else if( kk > ktop ) kd = kk-ktop ; else kd = 0 ;
01521            dijk = id+jd+kd+1 ;
01522            ff = (100.0f * ddd[ijk]) / (float)dijk - 98.9f ;
01523            if( ff > 255.0f ) ff = 255.0f ;
01524            sar[ijk] = (short)ff ;
01525          } else {
01526            sar[ijk] = 0 ;
01527          }
01528        }
01529        free((void *)ddd) ;
01530      }
01531      free((void *)mask); free((void *)ccc);
01532    }
01533 
01534    /* create a spat norm of the original volume ZSS */
01535    if (imout_origp) {
01536       mri_warp3D_method( MRI_NN ) ;
01537       if (1 && verb) fprintf(stderr,"thd_brainormalize (ZSS):\n n: %d %d %d\n d: %f %f %f\n o: %f %f %f\n ", sim_nx, sim_ny, sim_nz, sim_dx, sim_dy, sim_dz, sim_xo, sim_yo, sim_zo);
01538       imout_orig = mri_warp3D( tim, sim_nx, sim_ny, sim_nz, ijk_invwarp );
01539       imout_orig->dx = sim_dx; imout_orig->dy = sim_dy; imout_orig->dz = sim_dz; 
01540       imout_orig->xo = sim_xo; imout_orig->yo = sim_yo; imout_orig->zo = sim_zo; 
01541       *imout_origp = imout_orig;
01542    }
01543    
01544    if (imout_edge) { /* create an edge version NOT EXISTING YET */
01545       *imout_edge = NULL;
01546    }
01547       
01548    /*-- convert output to bytes --*/
01549 
01550    bim = mri_new_conforming( tim , MRI_byte ) ;
01551    MRI_COPY_AUX(bim,tim) ;
01552    bar = MRI_BYTE_PTR(bim) ;
01553 
01554    jj = 0 ;
01555    for( ii=0 ; ii < nxyz ; ii++ ) if( sar[ii] > jj ) jj = sar[ii] ;
01556 
01557    if( jj > 255 ){
01558      float fac = 255.0 / jj ;
01559      if( verb ) fprintf(stderr," + scaling by fac=%g\n",fac) ;
01560      for( ii=0 ; ii < nxyz ; ii++ ) bar[ii] = (byte)(fac*sar[ii]+0.49) ;
01561    } else {
01562      for( ii=0 ; ii < nxyz ; ii++ ) bar[ii] = (byte)sar[ii] ;
01563    }
01564    mri_free(tim) ;
01565 
01566    /*-- done!!! --*/
01567 
01568    RETURN(bim) ;
01569 }

void mri_brainormalize_initialize float    dx,
float    dy,
float    dz
 

Definition at line 13 of file thd_brainormalize.c.

References MIN, thd_bn_dxyz, thd_bn_nx, thd_bn_ny, and thd_bn_nz.

Referenced by main().

00014 {
00015    /* Set the reinterpolation resolution to the smallest delta */
00016    thd_bn_dxyz = MIN(fabs(dx), fabs(dy)); thd_bn_dxyz = MIN(thd_bn_dxyz, fabs(dz));
00017    thd_bn_nx = (int)( (float)thd_bn_nx / thd_bn_dxyz );
00018    thd_bn_ny = (int)( (float)thd_bn_ny / thd_bn_dxyz );
00019    thd_bn_nz = (int)( (float)thd_bn_nz / thd_bn_dxyz );
00020    return;
00021 }

void mri_brainormalize_verbose int   
 

Definition at line 8 of file thd_brainormalize.c.

References v, and verb.

Referenced by main().

00008 { verb = v ; }

NI_element* mri_to_niml MRI_IMAGE   im
 

Put an MRI_IMAGE into a NIML data element. -----------------------------------------------------------------------------

Definition at line 517 of file thd_nimlatr.c.

References MRI_IMAGE::dt, MRI_IMAGE::du, MRI_IMAGE::dv, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, MRI_IMAGE::kind, mri_data_pointer(), MRI_IMAGE::name, NI_add_column(), NI_new_data_element(), NI_set_attribute(), MRI_IMAGE::nt, MRI_IMAGE::nu, MRI_IMAGE::nv, MRI_IMAGE::nvox, MRI_IMAGE::nw, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, RETURN, MRI_IMAGE::to, MRI_IMAGE::uo, MRI_IMAGE::vo, MRI_IMAGE::wo, MRI_IMAGE::xo, MRI_IMAGE::yo, and MRI_IMAGE::zo.

Referenced by main().

00518 {
00519    NI_element *nel ;
00520    void *vpt ;
00521    char rhs[256] ;
00522 
00523 ENTRY("mri_to_niml") ;
00524 
00525    vpt = mri_data_pointer(im) ;
00526    if( vpt == NULL ) RETURN(NULL) ;
00527 
00528    nel = NI_new_data_element( "MRI_IMAGE" , im->nvox ) ;
00529 
00530    /* put in some attributes about the MRI_IMAGE struct */
00531  
00532    sprintf( rhs , "%d,%d,%d,%d,%d,%d,%d" ,
00533             im->nx , im->ny , im->nz , im->nt , im->nu , im->nv , im->nw ) ;
00534    NI_set_attribute( nel , "mri_dimen" , rhs ) ;
00535 
00536    if( im->dx != 0.0 || im->dy != 0.0 || im->dz != 0.0 ||
00537        im->dt != 0.0 || im->du != 0.0 || im->dv != 0.0 || im->dw != 0.0 ){
00538 
00539      sprintf( rhs , "%f,%f,%f,%f,%f,%f,%f" ,
00540               im->dx , im->dy , im->dz , im->dt , im->du , im->dv , im->dw ) ;
00541      NI_set_attribute( nel , "mri_dxyz" , rhs ) ;
00542    }
00543 
00544    if( im->xo != 0.0 || im->yo != 0.0 || im->zo != 0.0 ||
00545        im->to != 0.0 || im->uo != 0.0 || im->vo != 0.0 || im->wo != 0.0 ){
00546  
00547      sprintf( rhs , "%f,%f,%f,%f,%f,%f,%f" ,
00548               im->xo , im->yo , im->zo , im->to , im->uo , im->vo , im->wo ) ;
00549      NI_set_attribute( nel , "mri_xyzo" , rhs ) ;
00550    }
00551 
00552    if( im->name != NULL && im->name[0] != '\0' )
00553      NI_set_attribute( nel , "mri_name" , rhs ) ;
00554 
00555    /* put in the data */
00556     NI_add_column( nel , im->kind , vpt ) ;
00557 
00558    RETURN(nel) ;
00559 }

void mri_warp3D_align_cleanup MRI_warp3D_align_basis  
 

Definition at line 905 of file mri_warp3D_align.c.

References MRI_warp3D_align_basis::imap, MRI_warp3D_align_basis::imps, MRI_warp3D_align_basis::imps_blur, MRI_warp3D_align_basis::imsk, MRI_warp3D_align_basis::imww, and mri_free().

Referenced by main(), and mri_warp3D_align_setup().

00906 {
00907    if( bas == NULL ) return ;
00908    if( bas->imww != NULL ){ mri_free(bas->imww) ; bas->imww = NULL ; }
00909    if( bas->imap != NULL ){ mri_free(bas->imap) ; bas->imap = NULL ; }
00910    if( bas->imps != NULL ){ mri_free(bas->imps) ; bas->imps = NULL ; }
00911    if( bas->imsk != NULL ){ mri_free(bas->imsk) ; bas->imsk = NULL ; }
00912 
00913    if( bas->imps_blur != NULL ){ mri_free(bas->imps_blur) ; bas->imps_blur = NULL ; }
00914 }

MRI_IMAGE* mri_warp3d_align_one MRI_warp3D_align_basis  ,
MRI_IMAGE  
 

Definition at line 632 of file mri_warp3D_align.c.

References AFNI_noenv(), EDIT_blur_volume_3d(), ENTRY, far, fim, fit, MRI_warp3D_param_def::fixed, free, getenv(), i, MRI_warp3D_param_def::ident, MRI_warp3D_align_basis::imap, MRI_warp3D_align_basis::imps, MRI_warp3D_align_basis::imps_blur, MRI_warp3D_align_basis::imsk, MRI_IMAGE::kind, malloc, MRI_warp3D_param_def::max, MRI_warp3D_align_basis::max_iter, MRI_warp3D_param_def::min, MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, MRI_LINEAR, mri_to_float(), mri_warp3D(), mri_warp3D_method(), mri_warp3D_set_womask(), MRI_warp3D_align_basis::nfree, NI_clock_time(), MRI_warp3D_align_basis::nparam, MRI_warp3D_align_basis::num_iter, MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, nz, MRI_IMAGE::nz, P, MRI_warp3D_align_basis::param, MRI_IMAGE::pixel_size, MRI_warp3D_align_basis::regfinal, MRI_warp3D_align_basis::regmode, RETURN, s2, THD_MAX_NAME, MRI_warp3D_param_def::toler, MRI_warp3D_align_basis::twoblur, MRI_warp3D_param_def::val_fixed, MRI_warp3D_param_def::val_init, MRI_warp3D_param_def::val_out, MRI_warp3D_align_basis::verb, MRI_warp3D_align_basis::vwdet, MRI_warp3D_align_basis::vwfor, and MRI_warp3D_align_basis::vwset.

Referenced by main().

00633 {
00634    float *fit , *dfit , *qfit , *tol ;
00635    int iter , good,ngood , ii, pp , skip_first ;
00636    MRI_IMAGE *tim , *fim ;
00637    float *pmat=MRI_FLOAT_PTR(bas->imps) , /* pseudo inverse: n X m matrix */
00638          *tar , tv , sfit ;
00639    int n=bas->imps->nx ,          /* = nfree+1 */
00640        m=bas->imps->ny ,          /* = imap->nx = length of ima */
00641     npar=bas->nparam   ,          /* = number of warp parameters */
00642    nfree=bas->nfree    ,          /* = number of free warp parameters */
00643     *ima=MRI_INT_PTR(bas->imap) , /* = indexes in fim of voxels to use */
00644     *pma ;                        /* = map of free to total params */
00645    int ctstart ;
00646    int do_twopass=(bas->imps_blur != NULL && bas->twoblur > 0.0f) , passnum=1 ;
00647    char      *save_prefix ;
00648    static int save_index=0 ;
00649 
00650 #define AITMAX  3.33
00651 #define NMEM    5
00652    float *fitmem[NMEM] ;
00653    int mm , last_aitken , num_aitken=0 ;
00654 
00655 ENTRY("mri_warp3D_align_one") ;
00656 
00657    ctstart = NI_clock_time() ;
00658 
00659    save_prefix = getenv("AFNI_WARPDRIVE_SAVER") ;
00660 
00661    pma = (int *)malloc(sizeof(int) * nfree) ;
00662    for( pp=ii=0 ; ii < npar ; ii++ )
00663      if( !bas->param[ii].fixed ) pma[pp++] = ii ;
00664 
00665    fit  = (float *)malloc(sizeof(float) * npar ) ;
00666    dfit = (float *)malloc(sizeof(float) * npar ) ;
00667    qfit = (float *)malloc(sizeof(float) * nfree) ;
00668    tol  = (float *)malloc(sizeof(float) * npar ) ;
00669 
00670    for( mm=0 ; mm < NMEM ; mm++ ) fitmem[mm] = NULL ;
00671 
00672    /*--- loop back point for two pass alignment ---*/
00673 
00674    bas->num_iter = 0 ;
00675    mri_warp3D_set_womask( bas->imsk ) ;
00676 
00677  ReStart:
00678 
00679    mri_warp3D_method( (do_twopass && passnum==1) ? MRI_LINEAR : bas->regmode ) ;
00680 
00681    /* load initial fit parameters;
00682       if they are all the identity transform value,
00683       then skip the first transformation of the fim volume */
00684 
00685    if( passnum == 1 ){
00686      skip_first = 1 ;
00687      for( pp=0 ; pp < npar ; pp++ ){
00688        if( bas->param[pp].fixed ){
00689          fit[pp] = bas->param[pp].val_fixed ;
00690        } else {
00691          fit[pp] = bas->param[pp].val_init ;
00692          skip_first = skip_first && (fit[pp] == bas->param[pp].ident) ;
00693        }
00694      }
00695    } else {
00696      skip_first = 0 ;  /* and fit[] is unchanged */
00697    }
00698 
00699    fitmem[0] = (float *)malloc(sizeof(float)*npar) ;
00700    memcpy( fitmem[0] , fit , sizeof(float)*npar) ;
00701 
00702    for( pp=0 ; pp < npar ; pp++ ) tol[pp] = bas->param[pp].toler ;
00703 
00704    if( do_twopass && passnum == 1 ){
00705      float fac = (1.0f+bas->twoblur) ;
00706      if( fac < 3.0f ) fac = 3.0f ;
00707      for( pp=0 ; pp < npar ; pp++ ) tol[pp] *= fac ;
00708    }
00709 
00710    if( bas->verb ) fprintf(stderr,"++ mri_warp3d_align_one: START PASS #%d\n",passnum) ;
00711 
00712    /* setup base image for registration into fim,
00713       and pseudo-inverse of base+derivative images into pmat */
00714 
00715    if( do_twopass && passnum==1 ){    /* first pass ==> registering blurred images */
00716      float *far , blur=bas->twoblur ;
00717      int nx=im->nx , ny=im->ny , nz=im->nz ;
00718      fim = mri_to_float( im ) ; far = MRI_FLOAT_PTR(fim) ;
00719      EDIT_blur_volume_3d( nx,ny,nz ,       1.0f,1.0f,1.0f ,
00720                           MRI_float , far, blur,blur,blur  ) ;
00721      pmat = MRI_FLOAT_PTR(bas->imps_blur) ;
00722    } else {                           /* registering original image */
00723      if( im->kind == MRI_float ) fim = im ;
00724      else                        fim = mri_to_float( im ) ;
00725      pmat = MRI_FLOAT_PTR(bas->imps) ;
00726    }
00727 
00728    /*-- iterate fit --*/
00729 
00730    iter = 0 ; good = 1 ; last_aitken = 3 ;
00731    while( good ){
00732      if( skip_first ){
00733        tim = fim ; skip_first = 0 ;
00734      } else {
00735        bas->vwset( npar , fit ) ;
00736        tim = mri_warp3D( fim , 0,0,0 , bas->vwfor ) ; /* warp on current params */
00737      }
00738      tar = MRI_FLOAT_PTR(tim) ;
00739 
00740      /* find least squares fit of base + derivatives to warped image */
00741 
00742      sfit = 0.0f ;
00743      for( pp=0 ; pp < npar  ; pp++ ) dfit[pp] = 0.0f ;
00744      for( pp=0 ; pp < nfree ; pp++ ) qfit[pp] = 0.0f ;
00745      for( ii=0 ; ii < m ; ii++ ){
00746        tv = tar[ima[ii]] ; sfit += P(nfree,ii) * tv ;
00747        for( pp=0 ; pp < nfree ; pp++ ) qfit[pp] += P(pp,ii) * tv ;
00748      }
00749      if( tim != fim ) mri_free( tim ) ;
00750      for( pp=0 ; pp < nfree ; pp++ ) dfit[pp] = qfit[pma[pp]] ;
00751      for( pp=0 ; pp < npar  ; pp++ ){
00752        fit[pp] += dfit[pp] ;
00753             if( fit[pp] > bas->param[pp].max ) fit[pp] = bas->param[pp].max ;
00754        else if( fit[pp] < bas->param[pp].min ) fit[pp] = bas->param[pp].min ;
00755      }
00756 
00757      if( bas->verb ){
00758        fprintf(stderr,"+   Delta:") ;
00759        for( pp=0 ; pp < npar ; pp++ ) fprintf(stderr," %13.6g",dfit[pp]) ;
00760        fprintf(stderr,"\n") ;
00761        fprintf(stderr,"+   Total: scale factor=%g\n"
00762                       "+  #%5d:",sfit,iter+1) ;
00763        for( pp=0 ; pp < npar ; pp++ ) fprintf(stderr," %13.6g", fit[pp]) ;
00764        fprintf(stderr,"\n") ;
00765      }
00766 
00767      /* save fit results for a while into the past, and then maybe do Aitken */
00768 
00769      if( fitmem[NMEM-1] != NULL ) free((void *)fitmem[NMEM-1]) ;
00770      for( mm=NMEM-1 ; mm > 0 ; mm-- ) fitmem[mm] = fitmem[mm-1] ;
00771      fitmem[0] = (float *)malloc(sizeof(float)*npar) ;
00772      memcpy( fitmem[0] , fit , sizeof(float)*npar) ;
00773 
00774      iter++ ;
00775      if( iter > last_aitken+NMEM && !AFNI_noenv("AFNI_WARPDRIVE_AITKEN") ){
00776        double s0,s1,s2 , dd , de,df ;
00777        num_aitken = 0 ;
00778        for( pp=0 ; pp < npar ; pp++ ){
00779          dd = fabs(fitmem[1][pp]-fit[pp]) ;
00780          if( dd <= tol[pp] ) continue ; /* done here */
00781          de = dd ;
00782          for( mm=2 ; mm < NMEM ; mm++ ){
00783            df = fabs(fitmem[mm][pp]-fitmem[mm-1][pp]) ;
00784            if( df <= de ) break ;
00785            de = df ;
00786          }
00787          if( mm == NMEM ){  /* do Aitken */
00788            s2 = fit[pp] ; s1 = fitmem[1][pp] ; s0 = fitmem[2][pp] ;
00789            de = ( (s2-s1) - (s1-s0) ) ;
00790            if( de != 0.0 ){
00791              de = -(s2-s1)*(s2-s1) / de ; dd *= AITMAX ;
00792              if( fabs(de) > dd ){ de = (de > 0.0) ? dd : -dd ; }
00793              fit[pp] += de ;
00794                   if( fit[pp] > bas->param[pp].max ) fit[pp] = bas->param[pp].max ;
00795              else if( fit[pp] < bas->param[pp].min ) fit[pp] = bas->param[pp].min ;
00796              num_aitken++ ;
00797            }
00798          }
00799        }
00800        if( num_aitken > 0 ) last_aitken = iter ;
00801 
00802        if( bas->verb && num_aitken > 0 ){
00803          fprintf(stderr,"+   Aitken on %d params:\n"
00804                         "+________:",num_aitken) ;
00805          for( pp=0 ; pp < npar ; pp++ ){
00806            if( fit[pp] != fitmem[0][pp] ){
00807              fprintf(stderr," %13.6g", fit[pp]) ; fitmem[0][pp] = fit[pp] ;
00808            } else {
00809              fprintf(stderr," _____________") ;
00810            }
00811          }
00812          fprintf(stderr,"\n") ;
00813        }
00814      }
00815 
00816      /* save intermediate result? */
00817 
00818      if( save_prefix != NULL ){
00819        char sname[THD_MAX_NAME] ; FILE *fp ;
00820        mri_warp3D_set_womask( NULL ) ;
00821        bas->vwset( npar , fit ) ;
00822        tim = mri_warp3D( fim , 0,0,0 , bas->vwfor ) ;
00823        tar = MRI_FLOAT_PTR(tim) ;
00824        mri_warp3D_set_womask( bas->imsk ) ;
00825        sprintf(sname,"%s_%04d.mmm",save_prefix,save_index++) ;
00826        fprintf(stderr,"+   Saving intermediate image to binary file %s\n",sname) ;
00827        fp = fopen( sname , "w" ) ;
00828        if( fp != NULL ){
00829          fwrite( tar, tim->pixel_size, tim->nvox, fp ) ; fclose(fp) ;
00830        }
00831 
00832        if( bas->vwdet != NULL ){
00833          int i,j,k , nx=tim->nx,ny=tim->ny,nz=tim->nz ;
00834          for( k=0 ; k < nz ; k++ ){
00835           for( j=0 ; j < ny ; j++ ){
00836            for( i=0 ; i < nx ; i++ ){
00837              tar[i+(j+k*ny)*nx] = bas->vwdet( (float)i,(float)j,(float)k ) ;
00838          }}}
00839          sprintf(sname,"%s_%04d.ddd",save_prefix,save_index-1) ;
00840          fprintf(stderr,"+   Saving determinant image to binary file %s\n",sname) ;
00841          fp = fopen( sname , "w" ) ;
00842          if( fp != NULL ){
00843            fwrite( tar, tim->pixel_size, tim->nvox, fp ) ; fclose(fp) ;
00844          }
00845        }
00846        mri_free( tim ) ;
00847      }
00848 
00849      /* loop back for more iterations? */
00850 
00851      if( last_aitken == iter ) continue ;  /* don't test, just loop */
00852      if( fitmem[2]   == NULL ) continue ;
00853 
00854      ngood = 0 ;
00855      for( pp=0 ; pp < npar ; pp++ )
00856        if( !bas->param[pp].fixed )
00857          ngood += ( ( fabs(fitmem[1][pp]-fitmem[0][pp]) <= tol[pp] ) &&
00858                     ( fabs(fitmem[2][pp]-fitmem[1][pp]) <= tol[pp] )   ) ;
00859 
00860      good = (ngood < nfree) && (iter < bas->max_iter) ;
00861 
00862    } /* end while */
00863 
00864    bas->num_iter += iter ;
00865 
00866    for( mm=0 ; mm < NMEM ; mm++ )
00867      if( fitmem[mm] != NULL ){ free((void *)fitmem[mm]); fitmem[mm] = NULL; }
00868 
00869    /*--- do the second pass? ---*/
00870 
00871    if( do_twopass && passnum == 1 ){
00872      if( bas->verb )
00873        fprintf(stderr,"+++++++++++++ Loop back for next pass +++++++++++++\n");
00874      mri_free(fim) ; fim = NULL ; passnum++ ; goto ReStart ;
00875    } else {
00876      if( bas->verb )
00877        fprintf(stderr,"+++++++++++++ Convergence test passed +++++++++++++\n");
00878    }
00879 
00880    /*--- done! ---*/
00881 
00882    for( pp=0 ; pp < npar ; pp++ ) bas->param[pp].val_out = fit[pp] ;
00883 
00884    /*-- do the actual realignment to get the output image --*/
00885 
00886    if( bas->regfinal > 0 ) mri_warp3D_method( bas->regfinal ) ;
00887    mri_warp3D_set_womask( NULL ) ;
00888    bas->vwset( npar , fit ) ;
00889    tim = mri_warp3D( fim , 0,0,0 , bas->vwfor ) ;
00890 
00891    if( fim != im ) mri_free(fim) ;  /* if it was a copy, junk it */
00892    free((void *)dfit) ; free((void *)fit) ;
00893    free((void *)qfit) ; free((void *)pma) ; free((void *)tol) ;
00894 
00895    if( bas->verb ){
00896      double st = (NI_clock_time()-ctstart) * 0.001 ;
00897      fprintf(stderr,"++ mri_warp3d_align_one EXIT: %.2f seconds elapsed\n",st) ;
00898    }
00899 
00900    RETURN( tim ) ;
00901 }

int mri_warp3D_align_setup MRI_warp3D_align_basis  
 

Definition at line 387 of file mri_warp3D_align.c.

References MRI_warp3D_align_basis::delfac, EDIT_blur_volume_3d(), ENTRY, MRI_warp3D_param_def::fixed, free, MRI_warp3D_align_basis::imap, MRI_warp3D_align_basis::imbase, MRI_warp3D_align_basis::imsk, MRI_warp3D_align_basis::imwt, MRI_warp3D_align_basis::imww, malloc, MAX, MRI_warp3D_align_basis::max_iter, mmm, mri_copy(), MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, MRI_LINEAR, mri_max(), mri_new_conforming, mri_to_float(), mri_warp3D_align_cleanup(), mri_warp3D_align_edging_default(), MRI_warp3D_align_basis::nfree, NI_clock_time(), MRI_warp3D_align_basis::nparam, MRI_IMAGE::nx, MRI_IMAGE::ny, nz, MRI_IMAGE::nz, MRI_warp3D_align_basis::param, MRI_warp3D_align_basis::regmode, RETURN, MRI_warp3D_align_basis::scale_init, THD_cliplevel(), THD_mask_clust(), THD_mask_erode(), MRI_warp3D_align_basis::twoblur, MRI_warp3D_align_basis::verb, MRI_warp3D_align_basis::vwfor, MRI_warp3D_align_basis::vwinv, MRI_warp3D_align_basis::vwset, MRI_warp3D_align_basis::wtproc, WW, MRI_warp3D_align_basis::xedge, MRI_warp3D_align_basis::yedge, and MRI_warp3D_align_basis::zedge.

Referenced by main().

00388 {
00389    MRI_IMAGE *cim , *fitim ;
00390    int nx, ny, nz, nxy, nxyz , ii,jj,kk , nmap, *im ;
00391    float *wf , *wtar , clip , clip2 ;
00392    int   *ima , pp , wtproc , npar , nfree ;
00393    byte  *msk ;
00394    int ctstart ;
00395 
00396 ENTRY("mri_warp3D_align_setup") ;
00397 
00398    ctstart = NI_clock_time() ;
00399 
00400    /*- check for good inputs -*/
00401 
00402    if( bas == NULL     || bas->imbase == NULL ) RETURN(1) ;
00403    if( bas->nparam < 1 || bas->param  == NULL ) RETURN(1) ;
00404    if( bas->vwfor == NULL ||
00405        bas->vwinv == NULL || bas->vwset == NULL ) RETURN(1) ;
00406 
00407    /*- set defaults in bas, if values weren't set by user -*/
00408 
00409    if( bas->scale_init <= 0.0f ) bas->scale_init = 1.0f ;
00410    if( bas->delfac     <= 0.0f ) bas->delfac     = 1.0f ;
00411    if( bas->regmode    <= 0    ) bas->regmode    = MRI_LINEAR ;
00412    if( bas->max_iter   <= 0    ) bas->max_iter   = 9 ;
00413 
00414    /* process the weight image? */
00415 
00416    wtproc = (bas->imwt == NULL) ? 1 : bas->wtproc ;
00417    npar   = bas->nparam ;
00418 
00419    nfree = npar ;
00420    for( pp=0 ; pp < npar ; pp++ )
00421      if( bas->param[pp].fixed ) nfree-- ;
00422    if( nfree <= 0 ) RETURN(1) ;
00423    bas->nfree = nfree ;
00424 
00425    /*- clean out anything from last call -*/
00426 
00427    mri_warp3D_align_cleanup( bas ) ;
00428 
00429    /*-- need local copy of input base image --*/
00430 
00431    cim = mri_to_float( bas->imbase ) ;
00432    nx=cim->nx ; ny=cim->ny ; nz=cim->nz ; nxy = nx*ny ; nxyz=nxy*nz ;
00433 
00434    /*-- make weight image up from the base image if it isn't supplied --*/
00435 
00436    if( bas->verb ) fprintf(stderr,"++ mri_warp3D_align_setup ENTRY\n") ;
00437 
00438    if( bas->imwt == NULL   ||
00439        bas->imwt->nx != nx ||
00440        bas->imwt->ny != ny ||
00441        bas->imwt->nz != nz   ) bas->imww = mri_copy( cim ) ;
00442    else                        bas->imww = mri_to_float( bas->imwt ) ;
00443 
00444    if( bas->twoblur > 0.0f ){
00445      float bmax = (float)pow((double)nxyz,0.33333333) * 0.03 ;
00446      if( bmax < bas->twoblur ){
00447        if( bas->verb )
00448          fprintf(stderr,"+   shrink bas->twoblur from %.3f to %.3f\n",
00449                         bas->twoblur , bmax ) ;
00450        bas->twoblur = bmax ;
00451      }
00452    }
00453 
00454    if( bas->verb ) fprintf(stderr,"+   processing weight:") ;
00455 
00456    /* make sure weight is non-negative */
00457 
00458    wf = MRI_FLOAT_PTR(bas->imww) ;
00459    for( ii=0 ; ii < nxyz ; ii++ ) wf[ii] = fabs(wf[ii]) ;
00460 
00461    /* trim off edges of weight */
00462 
00463    if( wtproc ){
00464      int ff ;
00465      int xfade=bas->xedge , yfade=bas->yedge , zfade=bas->zedge ;
00466 
00467      if( xfade < 0 || yfade < 0 || zfade < 0 )
00468        mri_warp3D_align_edging_default(nx,ny,nz,&xfade,&yfade,&zfade) ;
00469 
00470      if( bas->twoblur > 0.0f ){
00471        xfade += (int)rint(1.5*bas->twoblur) ;
00472        yfade += (int)rint(1.5*bas->twoblur) ;
00473        zfade += (int)rint(1.5*bas->twoblur) ;
00474      }
00475 
00476      if( 3*zfade >= nz ) zfade = (nz-1)/3 ;
00477      if( 3*xfade >= nx ) xfade = (nx-1)/3 ;
00478      if( 3*yfade >= ny ) yfade = (ny-1)/3 ;
00479 
00480      if( bas->verb ) fprintf(stderr," [edge(%d,%d,%d)]",xfade,yfade,zfade) ;
00481 
00482      for( jj=0 ; jj < ny ; jj++ )
00483       for( ii=0 ; ii < nx ; ii++ )
00484        for( ff=0 ; ff < zfade ; ff++ )
00485          WW(ii,jj,ff) = WW(ii,jj,nz-1-ff) = 0.0f ;
00486 
00487      for( kk=0 ; kk < nz ; kk++ )
00488       for( jj=0 ; jj < ny ; jj++ )
00489        for( ff=0 ; ff < xfade ; ff++ )
00490          WW(ff,jj,kk) = WW(nx-1-ff,jj,kk) = 0.0f ;
00491 
00492      for( kk=0 ; kk < nz ; kk++ )
00493       for( ii=0 ; ii < nx ; ii++ )
00494        for( ff=0 ; ff < yfade ; ff++ )
00495         WW(ii,ff,kk) = WW(ii,ny-1-ff,kk) = 0.0f ;
00496 
00497    }
00498 
00499    /* spatially blur weight a little */
00500 
00501    if( wtproc ){
00502      float blur ;
00503      blur = 1.0f + MAX(1.5f,bas->twoblur) ;
00504      if( bas->verb ) fprintf(stderr," [blur(%.1f)]",blur) ;
00505      EDIT_blur_volume_3d( nx,ny,nz ,       1.0f,1.0f,1.0f ,
00506                           MRI_float , wf , blur,blur,blur  ) ;
00507    }
00508 
00509    /* get rid of low-weight voxels */
00510 
00511    clip  = 0.035 * mri_max(bas->imww) ;
00512    clip2 = 0.5*THD_cliplevel(bas->imww,0.4) ;
00513    if( clip2 > clip ) clip = clip2 ;
00514    if( bas->verb ) fprintf(stderr," [clip(%.1f)]",clip) ;
00515    for( ii=0 ; ii < nxyz ; ii++ ) if( wf[ii] < clip ) wf[ii] = 0.0f ;
00516 
00517    /* keep only the largest cluster of nonzero voxels */
00518 
00519    { byte *mmm = (byte *)malloc( sizeof(byte)*nxyz ) ;
00520      for( ii=0 ; ii < nxyz ; ii++ ) mmm[ii] = (wf[ii] > 0.0f) ;
00521      THD_mask_clust( nx,ny,nz, mmm ) ;
00522      THD_mask_erode( nx,ny,nz, mmm ) ;  /* cf. thd_automask.c */
00523      THD_mask_clust( nx,ny,nz, mmm ) ;
00524      for( ii=0 ; ii < nxyz ; ii++ ) if( !mmm[ii] ) wf[ii] = 0.0f ;
00525      free((void *)mmm) ;
00526    }
00527 
00528    if( bas->verb ) fprintf(stderr,"\n") ;
00529 
00530    /*-- make integer index map of weight > 0 voxels --*/
00531 
00532    nmap = 0 ;
00533    for( ii=0 ; ii < nxyz ; ii++ ) if( wf[ii] > 0.0f ) nmap++ ;
00534 
00535    if( bas->verb )
00536      fprintf(stderr,"+   using %d [%.3f%%] voxels\n",nmap,(100.0*nmap)/nxyz);
00537 
00538    if( nmap < 7*nfree+13 ){
00539      fprintf(stderr,"** mri_warp3D_align error: weight image too zero-ish!\n") ;
00540      mri_warp3D_align_cleanup( bas ) ; mri_free(cim) ;
00541      RETURN(1) ;
00542    }
00543 
00544    bas->imap = mri_new( nmap , 1 , MRI_int ) ;
00545    ima       = MRI_INT_PTR(bas->imap) ;
00546    bas->imsk = mri_new_conforming( bas->imww , MRI_byte ) ;
00547    msk       = MRI_BYTE_PTR(bas->imsk) ;
00548    for( ii=jj=0 ; ii < nxyz ; ii++ ){
00549      if( wf[ii] > 0.0f ){ ima[jj++] = ii; msk[ii] = 1; }
00550    }
00551 
00552    /* make copy of sqrt(weight), only at mapped indexes */
00553 
00554    wtar = (float *)malloc(sizeof(float)*nmap) ;
00555    for( ii=0 ; ii < nmap ; ii++ ) wtar[ii] = sqrt(wf[ima[ii]]) ;
00556 
00557    /*-- for parameters that don't come with a step size, find one --*/
00558 
00559    clip = bas->tolfac ; if( clip <= 0.0f ) clip = 0.03f ;
00560 
00561    for( ii=0 ; ii < npar ; ii++ ){
00562      if( bas->param[ii].fixed ) continue ; /* don't need this */
00563      if( bas->param[ii].delta <= 0.0f )
00564        mri_warp3D_get_delta( bas , ii ) ;  /* find step size */
00565      if( bas->param[ii].toler <= 0.0f ){   /* and set default tolerance */
00566        bas->param[ii].toler = clip * bas->param[ii].delta ;
00567        if( bas->verb )
00568          fprintf(stderr,"+   set toler param#%d [%s] = %f\n",
00569                  ii+1,bas->param[ii].name,bas->param[ii].toler) ;
00570      }
00571    }
00572 
00573    /* don't need the computed weight image anymore */
00574 
00575    mri_free(bas->imww) ; bas->imww = NULL ; wf = NULL ;
00576 
00577    /*-- create image containing basis columns, then pseudo-invert it --*/
00578 
00579    if( bas->verb ) fprintf(stderr,"+  Compute Derivatives of Base\n") ;
00580    fitim = mri_warp3D_align_fitim( bas , cim , bas->regmode , bas->delfac ) ;
00581    if( bas->verb ) fprintf(stderr,"+   calculate pseudo-inverse\n") ;
00582    bas->imps = mri_psinv( fitim , wtar ) ;
00583    mri_free(fitim) ;
00584 
00585    if( bas->imps == NULL ){  /* bad bad bad */
00586      fprintf(stderr,"** mri_warp3D_align error: can't invert Base matrix!\n") ;
00587      free((void *)wtar) ; mri_warp3D_align_cleanup( bas ) ; mri_free(cim) ;
00588      RETURN(1) ;
00589    }
00590 
00591    /*--- twoblur? ---*/
00592 
00593    if( bas->twoblur > 0.0f ){
00594      float *car=MRI_FLOAT_PTR(cim) ;
00595      float blur = bas->twoblur ;
00596      float bfac = blur ;
00597           if( bfac < 1.1234f ) bfac = 1.1234f ;
00598      else if( bfac > 1.3456f ) bfac = 1.3456f ;
00599 
00600      if( bas->verb ) fprintf(stderr,"+  Compute Derivatives of Blurred Base\n") ;
00601      EDIT_blur_volume_3d( nx,ny,nz ,       1.0f,1.0f,1.0f ,
00602                           MRI_float , car, blur,blur,blur  ) ;
00603      fitim = mri_warp3D_align_fitim( bas , cim , MRI_LINEAR , bfac*bas->delfac ) ;
00604      if( bas->verb ) fprintf(stderr,"+   calculate pseudo-inverse\n") ;
00605      bas->imps_blur = mri_psinv( fitim , wtar ) ;
00606      mri_free(fitim) ;
00607      if( bas->imps_blur == NULL ){  /* bad */
00608        fprintf(stderr,"** mri_warp3D_align error: can't invert Blur matrix!\n") ;
00609      }
00610    }
00611 
00612    /*--- done ---*/
00613 
00614    mri_free(cim) ; free((void *)wtar) ;
00615 
00616    if( bas->verb ){
00617      double st = (NI_clock_time()-ctstart) * 0.001 ;
00618      fprintf(stderr,"++ mri_warp3D_align_setup EXIT: %.2f seconds elapsed\n",st);
00619    }
00620 
00621    RETURN(0);
00622 }

MRI_IMAGE* mri_watershedize MRI_IMAGE  ,
float   
 

Definition at line 676 of file thd_brainormalize.c.

References ADDTO_BASIN, shortvox::basin, BDEP, calloc, DBALL, ENTRY, free, shortvox::i, i, IJK, INIT_BASIN, shortvox::j, shortvox::k, KILL_BASIN, MRI_IMAGE::kind, malloc, MERGE_BASIN, MRI_COPY_AUX, mri_new_conforming, MRI_SHORT_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, nz, MRI_IMAGE::nz, qsort_intint(), RETURN, sort_shortvox(), shortvox::val, and verb.

Referenced by main().

00677 {
00678    MRI_IMAGE *tim ;
00679    int ii,jj,kk , pp,qq , nx,ny,nz,nxy,nxyz , nvox ;
00680    int ip,jp,kp , im,jm,km ;
00681    short *sar , *tar ;
00682    shortvox *svox ;
00683    int *isvox , *bcount,*bname ;
00684    int nb,vb,mb,m,mu,mq,mz , bp[6] , hpf ;
00685 
00686    basin **baslist ;
00687    int nball , nbtop ;
00688 
00689 ENTRY("watershedize") ;
00690 
00691    if( sim == NULL || sim->kind != MRI_short ) RETURN(NULL) ;
00692    sar = MRI_SHORT_PTR(sim) ; if( sar == NULL ) RETURN(NULL) ;
00693 
00694    nx = sim->nx; ny = sim->ny; nz = sim->nz; nxy = nx*ny; nxyz = nxy*nz;
00695 
00696    /* count number of voxels > 0 */
00697 
00698    for( nvox=0,pp=0 ; pp < nxyz ; pp++ ) if( sar[pp] > 0 ) nvox++ ;
00699    if( nvox <= 999 ) RETURN(NULL) ;
00700 
00701    if( verb ) fprintf(stderr," + mri_watershedize: %d voxels input\n",nvox) ;
00702 
00703    /* create voxel lists */
00704 
00705    svox  = (shortvox *) malloc( sizeof(shortvox)* nvox ) ;
00706    isvox = (int *)      malloc( sizeof(int)     * nxyz ) ;
00707    for( qq=pp=0 ; pp < nxyz ; pp++ ){
00708      if( sar[pp] > 0 ){                  /* save this one: */
00709        ii             = pp % nx ;        /* spatial indexes */
00710        jj             = (pp%nxy) / nx ;
00711        kk             = pp / nxy ;
00712        svox[qq].i     = ii ;
00713        svox[qq].j     = jj ;
00714        svox[qq].k     = kk ;
00715        svox[qq].val   = sar[pp] ;        /* value */
00716        svox[qq].basin = -1 ;             /* which basin */
00717        qq++ ;
00718        isvox[pp]      = qq ;             /* where in list */
00719      } else {
00720        isvox[pp] = -1 ;                  /* voxel not in list */
00721      }
00722    }
00723 
00724    /* sort voxel list into descending order */
00725 
00726    if( verb ) fprintf(stderr," + mri_watershedize: sorting voxels\n") ;
00727 
00728    sort_shortvox( nvox , svox , 1 , 0.00 , 0.02 ) ;
00729 
00730    /* create basin for first (deepest) voxel */
00731 
00732    nball    = DBALL ;
00733    nbtop    = 0 ;
00734    baslist  = (basin **) calloc(sizeof(basin *),nball) ;
00735 
00736    INIT_BASIN(0) ;
00737 
00738    hpf      = (int)rint(prefac*svox[0].val) ;      /* preflood */
00739 
00740    /* scan voxels as they get shallower, and basinate them */
00741 
00742    if( verb ){
00743      fprintf(stderr," + mri_watershedize: basinating voxels\n") ;
00744      fprintf(stderr,"  data range: %d..%d preflood_height=%d\n",
00745              svox[nvox-1].val , svox[0].val , hpf ) ;
00746    }
00747 
00748    for( pp=1 ; pp < nvox ; pp++ ){
00749 
00750      ii = svox[pp].i; jj = svox[pp].j; kk = svox[pp].k;  /* where */
00751      ip = ii+1 ; jp = jj+1 ; kp = kk+1 ;                 /* nbhrs */
00752      im = ii-1 ; jm = jj-1 ; km = kk-1 ;
00753 
00754      if( verb && pp%100000 == 0 ) fprintf(stderr, (pp%1000000)?".":"!") ;
00755 
00756      /* macro checks if (a,b,c) voxel is in the list;
00757         if so and it is already in a basin, then
00758         make a list of basins encountered:
00759           nb = number of unique basins encountered (0..6)
00760           mb = index of deepest basin encountered (0..nb-1)
00761           vb = value (depth) of deepest basin encountered
00762           bp[m] = index of m-th basin encountered (m=0..nb-1) */
00763 
00764 #undef  BASECHECK
00765 #define BASECHECK(a,b,c)                                   \
00766     { qq = isvox[IJK(a,b,c)] ;                             \
00767       if( qq >= 0 && svox[qq].basin >= 0 ){                \
00768         qq = svox[qq].basin ;                              \
00769         for( m=0 ; m < nb && bp[m] != qq ; m++ ) ;         \
00770         if( m == nb ){                                     \
00771           bp[nb] = qq ;                                    \
00772           if( BDEP(qq) > vb ){ mb = nb; vb = BDEP(qq); }   \
00773           nb++ ;                                           \
00774         }                                                  \
00775       }                                                    \
00776     }
00777 
00778      nb = 0 ; vb = -1 ; mb = -1 ;         /* initialize counters */
00779      if( ip < nx ) BASECHECK(ip,jj,kk) ;  /* check each neighbor */
00780      if( im >= 0 ) BASECHECK(im,jj,kk) ;  /* for basin-ositiness */
00781      if( jp < ny ) BASECHECK(ii,jp,kk) ;
00782      if( jm >= 0 ) BASECHECK(ii,jm,kk) ;
00783      if( kp < nz ) BASECHECK(ii,jj,kp) ;
00784      if( km >= 0 ) BASECHECK(ii,jj,km) ;
00785 
00786      if( nb == 0 ){  /*** this voxel is isolated ==> create new basin ****/
00787 
00788        INIT_BASIN(pp) ;
00789 
00790      } else {        /*** this voxel has deeper neighbors ***/
00791 
00792        mq = bp[mb] ;                      /* assign voxel to best basin */
00793        ADDTO_BASIN( mq , pp ) ;
00794 
00795                        /* if have more than one neighbor, other */
00796        if( nb > 1 ){   /* basins could be merged with the best  */
00797          mz = svox[pp].val ;          /* depth of this voxel */
00798          for( m=0 ; m < nb ; m++ ){
00799            if( m == mb ) continue ;        /* can't merge with itself */
00800            mu = bp[m] ;
00801            if( BDEP(mu)-mz <= hpf ){       /* basin not TOO much deeper */
00802              MERGE_BASIN(mq,mu) ;
00803            }
00804          }
00805        }
00806      }
00807    } /* end of loop over voxels */
00808 
00809    /* at this point, all voxels in svox are assigned to a basin */
00810 
00811    free((void *)isvox) ;
00812 
00813    /* count number of basines left */
00814 
00815    for( mu=m=0 ; m < nbtop ; m++ )
00816      if( baslist[m] != NULL ) mu++ ;
00817 
00818    if( verb ) fprintf(stderr,"\n++ %d active basins left, out of %d\n",mu,nbtop) ;
00819 
00820    bcount = (int *) calloc(sizeof(int),mu) ;     /* number in each basin */
00821    bname  = (int *) calloc(sizeof(int),mu) ;
00822    isvox  = (int *) calloc(sizeof(int),nbtop) ;  /* new index */
00823 
00824    for( m=ii=0 ; m < nbtop ; m++ )
00825      if( baslist[m] != NULL ){ isvox[m] = ii; bname[ii] = ii; ii++; KILL_BASIN(m); }
00826    free((void *)baslist) ;
00827 
00828    for( pp=0 ; pp < nvox ; pp++ ){
00829      m  = svox[pp].basin ;           /* old basin name for this voxel */
00830      ii = isvox[m] ;                 /* new basin name for this voxel */
00831      svox[pp].basin = ii ;           /* reassign name in this voxel */
00832      bcount[ii]++ ;                  /* count number in this basin */
00833    }
00834 
00835    tim = mri_new_conforming( sim , MRI_short ) ;  /* output image */
00836    MRI_COPY_AUX(tim,sim) ;
00837    tar = MRI_SHORT_PTR(tim) ;
00838 
00839    for( ii=0 ; ii < mu ; ii++ ) bcount[ii] = -bcount[ii] ;
00840    qsort_intint( mu , bcount , bname ) ;  /* sort into decreasing order */
00841    for( ii=0 ; ii < mu ; ii++ ) bcount[ii] = -bcount[ii] ;
00842 
00843    if( verb )
00844      fprintf(stderr," + top 9 basin counts: %d %d %d %d %d %d %d %d %d\n",
00845              bcount[0] , bcount[1] , bcount[2] , bcount[3] ,
00846              bcount[4] , bcount[5] , bcount[6] , bcount[7] , bcount[8] ) ;
00847 
00848    for( ii=0 ; ii < mu ; ii++ ) isvox[ii] = ii ;
00849    qsort_intint( mu , bname , isvox ) ;
00850 
00851    for( pp=0 ; pp < nvox ; pp++ ){
00852      m = svox[pp].basin ; jj = isvox[m]+1 ; if( jj > 32767 ) jj = 32767 ;
00853      tar[IJK(svox[pp].i,svox[pp].j,svox[pp].k)] = jj ;
00854    }
00855 
00856    free((void *)isvox) ; free((void *)svox );
00857    free((void *)bcount); free((void *)bname);
00858 
00859    return tim ;
00860 }

MRI_IMAGE* niml_to_mri NI_element   nel
 

Convert a NIML element to an MRI_IMAGE. -----------------------------------------------------------------------------

Definition at line 565 of file thd_nimlatr.c.

References MRI_IMAGE::dt, MRI_IMAGE::du, MRI_IMAGE::dv, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, mri_add_name(), mri_data_pointer(), mri_new_7D_generic(), NI_element::name, NI_element_type(), NI_ELEMENT_TYPE, NI_get_attribute(), MRI_IMAGE::nvox, nz, MRI_IMAGE::pixel_size, RETURN, MRI_IMAGE::to, MRI_IMAGE::uo, NI_element::vec, NI_element::vec_len, NI_element::vec_num, NI_element::vec_typ, MRI_IMAGE::vo, MRI_IMAGE::wo, MRI_IMAGE::xo, MRI_IMAGE::yo, and MRI_IMAGE::zo.

Referenced by AIVVV_workproc(), and process_NIML_MRI_IMAGE().

00566 {
00567    char *rhs ;
00568    int   nx=1,ny=1,nz=1,nt=1,nu=1,nv=1,nw=1 ;
00569    MRI_IMAGE *im ;
00570    void *vpt ;
00571    int  nvox ;
00572 
00573 ENTRY("niml_to_mri") ;
00574 
00575    if( NI_element_type(nel)          != NI_ELEMENT_TYPE ||
00576        strcmp(nel->name,"MRI_IMAGE") != 0               ||
00577        nel->vec_num                  != 1               ||
00578        nel->vec_len                  <= 0                 ) RETURN(NULL) ;
00579 
00580    rhs = NI_get_attribute( nel , "mri_dimen" ) ;
00581    if( rhs == NULL ) RETURN(NULL) ;
00582    sscanf( rhs , "%d,%d,%d,%d,%d,%d,%d" ,
00583            &nx , &ny , &nz , &nt , &nu , &nv , &nw ) ;
00584    if( nx < 1 ) nx = 1 ;
00585    if( ny < 1 ) ny = 1 ;
00586    if( nz < 1 ) nz = 1 ;
00587    if( nt < 1 ) nt = 1 ;
00588    if( nu < 1 ) nu = 1 ;
00589    if( nv < 1 ) nv = 1 ;
00590    if( nw < 1 ) nw = 1 ;
00591 
00592    im = mri_new_7D_generic( nx,ny,nz,nt,nu,nv,nw ,
00593                             nel->vec_typ[0] , 1   ) ;
00594    if( im == NULL ) RETURN(NULL) ;
00595 
00596    vpt = mri_data_pointer(im) ;
00597    nvox = im->nvox ; if( nvox > nel->vec_len ) nvox = nel->vec_len ;
00598    memcpy( vpt , nel->vec[0] , im->pixel_size * nvox ) ;
00599 
00600    rhs = NI_get_attribute( nel , "mri_dxyz" ) ;
00601    if( rhs != NULL )
00602      sscanf( rhs , "%f,%f,%f,%f,%f,%f,%f" ,
00603              &(im->dx), &(im->dy), &(im->dz),
00604              &(im->dt), &(im->du), &(im->dv), &(im->dw) ) ;
00605 
00606    rhs = NI_get_attribute( nel , "mri_xyzo" ) ;
00607    if( rhs != NULL )
00608      sscanf( rhs , "%f,%f,%f,%f,%f,%f,%f" ,
00609              &(im->xo), &(im->yo), &(im->zo),
00610              &(im->to), &(im->uo), &(im->vo), &(im->wo) ) ;
00611 
00612    rhs = NI_get_attribute( nel , "mri_name" ) ;
00613    if( rhs != NULL ) mri_add_name( rhs , im ) ;
00614 
00615    RETURN(im) ;
00616 }

void nn_shift int   ,
float   ,
float *   
 

Definition at line 548 of file thd_shift2.c.

References ENTRY, FINS, free, lcbuf, malloc, and nlcbuf.

Referenced by nn_shift2().

00549 {
00550    int   ii , ia , ix ;
00551 
00552 ENTRY("nn_shift") ;
00553 
00554    af = -af ; ia = (int) af ; if( af < 0 ) ia-- ;  /* ia = floor */
00555 
00556    /* 15 Mar 2001: if shift is too large, return all zeros */
00557 
00558    if( ia <= -n || ia >= n ){
00559       for( ii=0 ; ii < n ; ii++ ) f[ii] = 0.0 ;
00560       EXRETURN ;
00561    }
00562 
00563    if( n > nlcbuf ){
00564       if( lcbuf != NULL ) free(lcbuf) ;
00565       lcbuf  = (float *) malloc( sizeof(float) * n ) ;
00566       nlcbuf = n ;
00567    }
00568 
00569    for( ii=0 ; ii < n ; ii++ ){
00570       ix = ii + ia ;
00571       lcbuf[ii] = FINS(ix) ;
00572    }
00573 
00574    memcpy( f , lcbuf , sizeof(float)*n ) ;
00575    EXRETURN ;
00576 }

void nn_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 578 of file thd_shift2.c.

References nn_shift().

Referenced by SHIFT_set_method().

00579 {
00580                    nn_shift( n , af , f ) ;
00581    if( g != NULL ) nn_shift( n , ag , g ) ;
00582    return ;
00583 }

void quint_shift int   ,
float   ,
float *   
 

Definition at line 304 of file thd_shift2.c.

References ENTRY, FINS, free, lcbuf, malloc, nlcbuf, Q_00, Q_M1, Q_M2, Q_P1, Q_P2, and Q_P3.

Referenced by quint_shift2().

00305 {
00306    int   ii , ia , ix ;
00307    float  wt_m1 , wt_00 , wt_p1 , wt_p2 , aa , wt_m2 , wt_p3 ;
00308 #ifdef SEPARATE_FINS
00309    int ibot,itop ;
00310 #endif
00311 
00312 ENTRY("quint_shift") ;
00313 
00314    af = -af ; ia = (int) af ; if( af < 0 ) ia-- ;  /* ia = floor */
00315 
00316    /* 15 Mar 2001: if shift is too large, return all zeros */
00317 
00318    if( ia <= -n || ia >= n ){
00319       for( ii=0 ; ii < n ; ii++ ) f[ii] = 0.0 ;
00320       EXRETURN ;
00321    }
00322 
00323    aa = af - ia ;
00324    wt_m1 = Q_M1(aa) ; wt_00 = Q_00(aa) ;
00325    wt_p1 = Q_P1(aa) ; wt_p2 = Q_P2(aa) ;
00326    wt_m2 = Q_M2(aa) ; wt_p3 = Q_P3(aa) ;
00327 
00328    if( n > nlcbuf ){
00329       if( lcbuf != NULL ) free(lcbuf) ;
00330       lcbuf  = (float *) malloc( sizeof(float) * n ) ;
00331       nlcbuf = n ;
00332    }
00333 
00334 #ifdef SEPARATE_FINS
00335    ibot = 2-ia ;   if( ibot < 0   ) ibot = 0 ;
00336    itop = n-4-ia ; if( itop > n-1 ) itop = n-1 ;
00337 
00338    for( ii=ibot ; ii <= itop ; ii++ ){
00339       ix = ii + ia ;
00340       lcbuf[ii] =  wt_m2 * f[ix-2] + wt_m1 * f[ix-1] + wt_00 * f[ix]
00341                  + wt_p1 * f[ix+1] + wt_p2 * f[ix+2] + wt_p3 * f[ix+3] ;
00342    }
00343 
00344    if( ibot > n ) ibot = n ; /* 15 Mar 2001 */
00345    for( ii=0 ; ii < ibot ; ii++ ){
00346       ix = ii + ia ;
00347       lcbuf[ii] =  wt_m2 * FINS(ix-2) + wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00348                  + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) + wt_p3 * FINS(ix+3) ;
00349    }
00350 
00351    if( itop < 0 ) itop = -1 ; /* 15 Mar 2001 */
00352    for( ii=itop+1 ; ii < n ; ii++ ){
00353       ix = ii + ia ;
00354       lcbuf[ii] =  wt_m2 * FINS(ix-2) + wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00355                  + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) + wt_p3 * FINS(ix+3) ;
00356    }
00357 #else /* not SEPARATE_FINS */
00358    for( ii=0 ; ii < n ; ii++ ){
00359       ix = ii + ia ;
00360       if( ix > 1 && ix < n-3 )
00361          lcbuf[ii] =  wt_m2 * f[ix-2] + wt_m1 * f[ix-1] + wt_00 * f[ix]
00362                     + wt_p1 * f[ix+1] + wt_p2 * f[ix+2] + wt_p3 * f[ix+3] ;
00363       else
00364          lcbuf[ii] =  wt_m2 * FINS(ix-2) + wt_m1 * FINS(ix-1) + wt_00 * FINS(ix)
00365                     + wt_p1 * FINS(ix+1) + wt_p2 * FINS(ix+2) + wt_p3 * FINS(ix+3) ;
00366    }
00367 #endif /* SEPARATE_FINS */
00368 
00369    memcpy( f , lcbuf , sizeof(float)*n ) ;
00370    EXRETURN ;
00371 }

void quint_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 373 of file thd_shift2.c.

References quint_shift().

Referenced by SHIFT_set_method().

00374 {
00375                    quint_shift( n , af , f ) ;
00376    if( g != NULL ) quint_shift( n , ag , g ) ;
00377    return ;
00378 }

int SARR_find_string THD_string_array   sar,
char *    str
 

Definition at line 19 of file thd_sarr.c.

References SARR_lookfor_string().

00020 {
00021    return SARR_lookfor_string( sar , str , 0 ) ;
00022 }

int SARR_find_substring THD_string_array   sar,
char *    sub
 

Definition at line 24 of file thd_sarr.c.

References SARR_lookfor_substring().

00025 {
00026    return SARR_lookfor_substring( sar , str , 0 ) ;
00027 }

int SARR_lookfor_string THD_string_array   sar,
char *    str,
int    nstart
 

Definition at line 29 of file thd_sarr.c.

References THD_string_array::ar, and THD_string_array::num.

Referenced by SARR_find_string(), and THD_normalize_flist().

00030 {
00031    int ii ;
00032 
00033    if( sar == NULL || str == NULL ) return -1 ;
00034 
00035    for( ii=nstart ; ii < sar->num ; ii++ ){
00036       if( sar->ar[ii] != NULL && strcmp(sar->ar[ii],str) == 0 )
00037          return ii ;
00038    }
00039    return -1 ;
00040 }

int SARR_lookfor_substring THD_string_array   sar,
char *    sub,
int    nstart
 

Definition at line 42 of file thd_sarr.c.

References THD_string_array::ar, and THD_string_array::num.

Referenced by SARR_find_substring(), and THD_init_prefix_datablocks().

00043 {
00044    int ii ;
00045 
00046    if( sar == NULL || sub == NULL ) return -1 ;
00047 
00048    for( ii=nstart ; ii < sar->num ; ii++ ){
00049       if( sar->ar[ii] != NULL && strstr(sar->ar[ii],sub) != NULL )
00050          return ii ;
00051    }
00052    return -1 ;
00053 }

int SHIFT_get_method void   
 

Definition at line 38 of file thd_shift2.c.

References shift_method.

Referenced by main().

00038 { return shift_method ; }

void SHIFT_set_method int   
 

Definition at line 20 of file thd_shift2.c.

References cub_shift2(), fft_shift2(), hept_shift2(), lin_shift2(), MRI_CUBIC, MRI_FOURIER, MRI_HEPTIC, MRI_LINEAR, MRI_NN, MRI_QUINTIC, MRI_TSSHIFT, nn_shift2(), quint_shift2(), shift_method, shifter, and ts_shift2().

Referenced by main(), and THD_dataset_tshift().

00021 {
00022    shift_method = mode ;
00023    switch( mode ){
00024       default:          shift_method = MRI_FOURIER ;  /* fall thru */
00025       case MRI_FOURIER: shifter = fft_shift2   ; break ;
00026 
00027       case MRI_LINEAR:  shifter = lin_shift2   ; break ;
00028       case MRI_CUBIC:   shifter = cub_shift2   ; break ;
00029       case MRI_QUINTIC: shifter = quint_shift2 ; break ;  /* Nov 1998 */
00030       case MRI_HEPTIC:  shifter = hept_shift2  ; break ;  /* Nov 1998 */
00031 
00032       case MRI_NN:      shifter = nn_shift2    ; break ;  /* experimental */
00033       case MRI_TSSHIFT: shifter = ts_shift2    ; break ;  /* Dec 1999 */
00034    }
00035    return ;
00036 }

void SHIFT_two_rows int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 44 of file thd_shift2.c.

References shifter().

Referenced by main(), and THD_dataset_tshift().

00045 {
00046    shifter( n,nup,af,f,ag,g ) ; return ;
00047 }

THD_fvec3 THD_3dfind_to_3dmm THD_3dim_dataset  ,
THD_fvec3   
 

Definition at line 30 of file thd_coords.c.

References CURRENT_DAXES, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by THD_autonudge(), and THD_cmass().

00032 {
00033    THD_dataxes * daxes ;
00034    THD_fvec3     fv ;
00035 
00036    daxes = CURRENT_DAXES(dset) ;
00037 
00038    fv.xyz[0] = daxes->xxorg + iv.xyz[0] * daxes->xxdel ;
00039    fv.xyz[1] = daxes->yyorg + iv.xyz[1] * daxes->yydel ;
00040    fv.xyz[2] = daxes->zzorg + iv.xyz[2] * daxes->zzdel ;
00041    return fv ;
00042 }

THD_fvec3 THD_3dfind_to_fdfind FD_brick  ,
THD_fvec3   
 

Definition at line 306 of file thd_coords.c.

References FD_brick::a123, abs, THD_ivec3::ijk, FD_brick::sxyz, and THD_fvec3::xyz.

Referenced by AFNI_brick_to_mri().

00307 {
00308    THD_fvec3 ib ;
00309    int qq , ax ;
00310 
00311    for( qq=0 ; qq < 3 ; qq++ ){
00312       ax = abs( br->a123.ijk[qq] ) - 1 ;
00313 
00314       if( br->a123.ijk[qq] > 0 ) ib.xyz[qq] = id.xyz[ax] ;
00315       else                       ib.xyz[qq] = br->sxyz.ijk[ax] - id.xyz[ax];
00316    }
00317 
00318    return ib ;
00319 }

FD_brick* THD_3dim_dataset_to_brick THD_3dim_dataset  ,
int   ,
int   ,
int   
 

Definition at line 194 of file thd_fdbrick.c.

References FD_brick::a123, abs, CURRENT_DAXES, FD_brick::d1, FD_brick::d2, FD_brick::d3, FD_brick::del1, FD_brick::del2, FD_brick::del3, FD_brick::dset, FD_brick::e1, FD_brick::e2, ISVALID_3DIM_DATASET, LOAD_IVEC3, myXtNew, FD_brick::n1, FD_brick::n2, FD_brick::n3, FD_brick::namecode, THD_dataxes::nxx, FD_brick::nxyz, THD_dataxes::nyy, nz, THD_dataxes::nzz, FD_brick::parent, FD_brick::resam_code, RESAM_NN_TYPE, FD_brick::start, FD_brick::sxyz, FD_brick::thr_resam_code, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by T3D_open_view_CB(), THD_oriented_brick(), and THD_setup_bricks().

00196 {
00197    FD_brick      * br ;    /* will be output */
00198    THD_dataxes   * daxes ; /* connection to actual axes */
00199 
00200    int   xyz_dim[4] , xyz_stp[4] , xyz_dir[4] ;
00201    float xyz_del[4] , xyz_org[4] ;
00202 
00203    int x_dir,y_dir,z_dir , sx,sy,sz , aax_1,aax_2,aax_3 , nx,ny,nz ;
00204 
00205    /*-- sanity check --*/
00206 
00207    if( ! ISVALID_3DIM_DATASET(dset) ) return NULL ;
00208 
00209    daxes = CURRENT_DAXES(dset) ;
00210 
00211    aax_1 = abs(ax_1) ;  /* which axes, regardless of + or - */
00212    aax_2 = abs(ax_2) ;
00213    aax_3 = abs(ax_3) ;
00214 
00215    if( aax_1 < 1 || aax_1 > 3 ||   /* range checks */
00216        aax_2 < 1 || aax_2 > 3 ||
00217        aax_3 < 1 || aax_3 > 3   ) return NULL ;
00218 
00219    xyz_dir[1] = xyz_dir[2] = xyz_dir[3] = 0 ;
00220 
00221    xyz_dir[aax_1] = ax_1 ;  /* assign to original directions */
00222    xyz_dir[aax_2] = ax_2 ;
00223    xyz_dir[aax_3] = ax_3 ;
00224 
00225    x_dir = xyz_dir[1] ;  /* if any |ax_n| is duplicated */
00226    y_dir = xyz_dir[2] ;  /* then one of these will end  */
00227    z_dir = xyz_dir[3] ;  /* up as zero --> bad inputs!  */
00228 
00229    if( x_dir == 0 || y_dir == 0 || z_dir == 0 ) return NULL ;
00230 
00231    /*-- the inputs are good, so create a brick: --*/
00232 
00233    br             = myXtNew(FD_brick) ;  /* new brick */
00234    br->dset       = dset ;               /* dataset */
00235    br->resam_code = RESAM_NN_TYPE ;      /* crudest type */
00236    br->parent     = NULL ;
00237 
00238    br->thr_resam_code = RESAM_NN_TYPE ;  /* 09 Dec 1997 */
00239 
00240    /*-- at this point, x_dir is +1 or -1, y_dir is +2 or -2, etc. --*/
00241 
00242    nx = daxes->nxx ; ny = daxes->nyy ; nz = daxes->nzz ;
00243 
00244    sx = (x_dir > 0) ? (0) : (nx-1) ;  /* starting voxel indices */
00245    sy = (y_dir > 0) ? (0) : (ny-1) ;  /* for each original dimension */
00246    sz = (z_dir > 0) ? (0) : (nz-1) ;
00247 
00248    br->start = sx + sy*nx + sz*nx*ny ; /* overall starting voxel index */
00249 
00250    /*-- assign original dimensions to arrays,
00251         then pick out the permuted dimensions --*/
00252 
00253    xyz_dim[1] = nx ;  /* dimensions */
00254    xyz_dim[2] = ny ;
00255    xyz_dim[3] = nz ;
00256 
00257    LOAD_IVEC3( br->nxyz , nx,ny,nz ) ;       /* save stuff in br */
00258    LOAD_IVEC3( br->sxyz , sx,sy,sz ) ;
00259    LOAD_IVEC3( br->a123 , ax_1,ax_2,ax_3 ) ;
00260 
00261    xyz_stp[1] = 1 ;            /* index step sizes */
00262    xyz_stp[2] = nx ;
00263    xyz_stp[3] = nx * ny ;
00264 
00265    xyz_del[1] = daxes->xxdel ; /* voxel physical step sizes (mm) */
00266    xyz_del[2] = daxes->yydel ;
00267    xyz_del[3] = daxes->zzdel ;
00268 
00269    xyz_org[1] = daxes->xxorg ; /* voxel origins (mm) */
00270    xyz_org[2] = daxes->yyorg ;
00271    xyz_org[3] = daxes->zzorg ;
00272 
00273    br->n1 = xyz_dim[aax_1] ;   /* permute dimensions, etc. */
00274    br->n2 = xyz_dim[aax_2] ;
00275    br->n3 = xyz_dim[aax_3] ;
00276 
00277    br->d1 = (ax_1 > 0) ? (xyz_stp[aax_1]) : (-xyz_stp[aax_1]) ;
00278    br->d2 = (ax_2 > 0) ? (xyz_stp[aax_2]) : (-xyz_stp[aax_2]) ;
00279    br->d3 = (ax_3 > 0) ? (xyz_stp[aax_3]) : (-xyz_stp[aax_3]) ;
00280 
00281    br->e1 = br->n1 * br->d1 ;  /* last indices for readout */
00282    br->e2 = br->n2 * br->d2 ;
00283 
00284    br->del1 = fabs(xyz_del[aax_1]) ;  /* dimensions */
00285    br->del2 = fabs(xyz_del[aax_2]) ;
00286    br->del3 = fabs(xyz_del[aax_3]) ;
00287 
00288    br->namecode[0] = '\0' ;
00289 
00290    return br ;
00291 }

THD_3dim_dataset* THD_3dim_from_block THD_datablock   blk
 

Given a datablock, make it into a 3D dataset if possible. ---------------------------------------------------------------------

Definition at line 27 of file thd_dsetdblk.c.

References ADDTO_KILL, THD_marker_set::aflags, allow_nodata, THD_3dim_dataset::anat_parent, THD_3dim_dataset::anat_parent_idcode, THD_3dim_dataset::anat_parent_name, ATRNAME_ANATOMY_PARENT, ATRNAME_BRICK_STATS, ATRNAME_DATANAME, ATRNAME_DELTA, ATRNAME_IDANATPAR, ATRNAME_IDDATE, ATRNAME_IDSTRING, ATRNAME_IDWARPPAR, ATRNAME_KEYWORDS, ATRNAME_LABEL1, ATRNAME_LABEL2, ATRNAME_MARKSFLAG, ATRNAME_MARKSHELP, ATRNAME_MARKSLAB, ATRNAME_MARKSXYZ, ATRNAME_MINMAX, ATRNAME_ORIENT_SPECIFIC, ATRNAME_ORIGIN, ATRNAME_SCENE_TYPE, ATRNAME_STAT_AUX, ATRNAME_TAGSET_FLOATS, ATRNAME_TAGSET_LABELS, ATRNAME_TAGSET_NUM, ATRNAME_TAXIS_FLOATS, ATRNAME_TAXIS_NUMS, ATRNAME_TAXIS_OFFSETS, ATRNAME_TYPESTRING, ATRNAME_WARP_DATA, ATRNAME_WARP_PARENT, ATRNAME_WARP_TYPE, THD_statistics::bstat, ATR_string::ch, COPY_INTO_STRUCT, DATAXES_TYPE, MCW_idcode::date, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_3dim_dataset::death_mark, THD_diskptr::dimsizes, THD_datablock::diskptr, DSET_ERR, DSET_ERRN, DSET_HEADNAME, DSET_ONDISK, THD_timeaxis::dz_sl, ENTRY, FIRST_3DIM_TYPE, ATR_float::fl, THD_3dim_dataset::func_type, THD_diskptr::header_name, THD_marker_set::help, THD_3dim_dataset::idcode, ATR_int::in, INIT_KILL, INIT_STAT_AUX, INVALIDATE_BSTAT, ISFUNC, ISFUNCTYPE, ISVALID_DATABLOCK, ISVALID_DISKPTR, ISZERO_IDCODE, THD_3dim_dataset::keywords, THD_3dim_dataset::kl, THD_marker_set::label, THD_usertaglist::label, THD_usertag::label, THD_3dim_dataset::label1, THD_3dim_dataset::label2, LAST_3DIM_TYPE, LOAD_ZERO_MAT, MAPPING_LINEAR_FSIZE, MAPPING_LINEAR_FSTART, MAPPING_LINEAR_TYPE, THD_3dim_dataset::markers, MARKS_ASIZE, MARKS_ASTART, MARKS_FSIZE, MARKS_FSTART, MARKS_HSIZE, MARKS_HSTART, MARKS_LSIZE, MARKS_LSTART, MARKS_MAXFLAG, MARKS_MAXNUM, THD_mat33::mat, THD_brick_stats::max, MAX_TAG_NUM, MCW_IDDATE, MCW_IDSIZE, MCW_new_idcode, MCW_strncpy, THD_brick_stats::min, myXtNew, THD_statistics::nbstat, ATR_string::nch, ATR_float::nfl, ATR_int::nin, THD_timeaxis::nsl, THD_timeaxis::ntt, THD_usertaglist::num, THD_marker_set::numdef, THD_marker_set::numset, THD_diskptr::nvals, THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, THD_marker_set::ovcolor, THD_datablock::parent, THD_3dim_dataset::parent, THD_dataxes::parent, THD_statistics::parent, THD_diskptr::rank, THD_affine_warp::resam_type, THD_talairach_12_warp::resam_type, RETURN, THD_3dim_dataset::self_name, THD_3dim_dataset::self_warp, THD_usertag::set, STATISTICS_TYPE, THD_3dim_dataset::stats, STATUS, MCW_idcode::str, THD_usertaglist::tag, TAG_SETLABEL, THD_3dim_dataset::tagset, THD_3dim_dataset::taxis, THD_3dim_dataset::tcat_len, THD_3dim_dataset::tcat_list, THD_3dim_dataset::tcat_num, THD_datablock_apply_atr(), THD_DEFAULT_LABEL, THD_delete_3dim_dataset(), THD_FATAL_ERROR, THD_find_float_atr(), THD_find_int_atr(), THD_find_string_atr(), THD_MAX_LABEL, THD_MAX_NAME, THD_write_3dim_dataset(), THD_usertag::ti, TIMEAXIS_TYPE, THD_dataxes::to_dicomm, THD_timeaxis::toff_sl, THD_timeaxis::ttdel, THD_timeaxis::ttdur, THD_timeaxis::ttorg, THD_3dim_dataset::type, THD_dataxes::type, THD_marker_set::type, THD_affine_warp::type, THD_linear_mapping::type, THD_talairach_12_warp::type, THD_statistics::type, THD_timeaxis::type, UNITS_MSEC_TYPE, THD_timeaxis::units_type, THD_usertag::val, THD_marker_set::valid, THD_3dim_dataset::view_type, THD_3dim_dataset::vox_warp, THD_3dim_dataset::warp, THD_affine_warp::warp, THD_talairach_12_warp::warp, WARP_AFFINE_TYPE, THD_3dim_dataset::warp_parent, THD_3dim_dataset::warp_parent_idcode, THD_3dim_dataset::warp_parent_name, WARP_TALAIRACH_12_TYPE, THD_3dim_dataset::wod_daxes, THD_3dim_dataset::wod_flag, THD_usertag::x, XtMalloc, THD_dataxes::xxdel, THD_dataxes::xxmax, THD_dataxes::xxmin, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_marker_set::xyz, THD_usertag::y, THD_dataxes::yydel, THD_dataxes::yymax, THD_dataxes::yymin, THD_dataxes::yyorg, THD_dataxes::yyorient, THD_usertag::z, ZERO_IDCODE, ZERO_STAT_AUX, THD_timeaxis::zorg_sl, THD_dataxes::zzdel, THD_dataxes::zzmax, THD_dataxes::zzmin, THD_dataxes::zzorg, and THD_dataxes::zzorient.

Referenced by THD_array_3dim_from_block(), THD_niml_to_dataset(), and THD_open_one_dataset().

00028 {
00029    THD_3dim_dataset *dset ;
00030    THD_diskptr      *dkptr ;
00031    THD_dataxes      *daxes ;
00032 
00033    Boolean dset_ok = True ;
00034    int iq ;
00035 
00036    ATR_int    *atr_int ;
00037    ATR_string *atr_str ;
00038    ATR_float  *atr_flo ;
00039 
00040 #if 0
00041    int new_idcode = 0 ;   /* no longer needed */
00042 #endif
00043 
00044 ENTRY("THD_3dim_from_block") ; /* 29 Aug 2001 */
00045 
00046    /* sanity check */
00047 
00048    if( ! ISVALID_DATABLOCK(blk) || ! ISVALID_DISKPTR(blk->diskptr) )
00049       RETURN( NULL );
00050 
00051    /*-- initialize a new 3D dataset --*/
00052 
00053    dset       = myXtNew( THD_3dim_dataset ) ;  /* uses XtCalloc() */
00054    dset->dblk = blk  ;
00055    dkptr      = blk->diskptr ;
00056 
00057    if( PRINT_TRACING ){
00058      char str[256] ;
00059      sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d",
00060              dkptr->rank , dkptr->nvals ,
00061              dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] ) ;
00062      STATUS(str) ;
00063    }
00064 
00065    INIT_KILL(dset->kl) ;
00066    ADDTO_KILL(dset->kl,blk) ;
00067 
00068    blk->parent  = (XtPointer) dset ;
00069    dset->parent = NULL ;
00070 
00071    daxes = dset->daxes = myXtNew(THD_dataxes) ;
00072    daxes->parent = (XtPointer) dset ;
00073 
00074    dset->wod_daxes = NULL ;  /* 02 Nov 1996 */
00075 
00076    dset->wod_flag    = False ;  /* set special flags */
00077    dset->death_mark  = 0 ;
00078    dset->tcat_list   = NULL ;
00079    dset->tcat_num    = 0 ;
00080    dset->tcat_len    = NULL ;
00081 
00082    ADDTO_KILL(dset->kl,daxes) ;
00083 
00084    dset->stats  = NULL ;
00085 #ifdef ALLOW_DATASET_VLIST
00086    dset->pts    = NULL ;
00087 #endif
00088    dset->taxis  = NULL ;
00089    dset->tagset = NULL ;   /* 23 Oct 1998 */
00090 
00091    /*------------------*/
00092    /*-- check for 3D --*/
00093    /*------------------*/
00094 
00095    if( dkptr->rank != 3 ) DSET_ERRN("illegal # of dimensions",dkptr->rank) ;
00096 
00097    /*--------------------------------------------------*/
00098    /*-- find type of image from TYPESTRING attribute --*/
00099    /*--------------------------------------------------*/
00100 
00101    atr_str = THD_find_string_atr( blk , ATRNAME_TYPESTRING ) ;
00102    if( atr_str == NULL ){
00103       DSET_ERR("no TYPESTRING") ;
00104       dset->type = -1 ;
00105    } else {
00106       int type ;
00107       for( type=FIRST_3DIM_TYPE ; type <= LAST_3DIM_TYPE ; type++ )
00108          if( strcmp( atr_str->ch , DATASET_typestr[type] ) == 0 ) break ;
00109 
00110       if( type > LAST_3DIM_TYPE ) DSET_ERR("illegal TYPESTRING") ;
00111       dset->type = type ;
00112    }
00113 
00114    /*-------------------------------------------------------*/
00115    /*-- find view_type and func_type from SCENE_TYPE data --*/
00116    /*-------------------------------------------------------*/
00117 
00118    atr_int = THD_find_int_atr( blk , ATRNAME_SCENE_TYPE ) ;
00119    if( atr_int == NULL ){
00120       DSET_ERR("missing or illegal SCENE_TYPE") ;
00121    } else {
00122       dset->view_type = atr_int->in[0] ;
00123       dset->func_type = atr_int->in[1] ;
00124 
00125       if( dset->type != atr_int->in[2] ){
00126          DSET_ERR("non-matching SCENE_TYPE[2]") ;
00127       }
00128    }
00129 
00130    /*-------------------------------------------------------*/
00131    /*--               find identifier codes               --*/
00132    /*-------------------------------------------------------*/
00133 
00134 #ifndef USE_APPLICATOR
00135    atr_str = THD_find_string_atr( blk , ATRNAME_IDSTRING ) ;
00136    if( atr_str != NULL ){
00137      MCW_strncpy( dset->idcode.str , atr_str->ch , MCW_IDSIZE ) ;
00138      atr_str = THD_find_string_atr( blk , ATRNAME_IDDATE ) ;
00139      if( atr_str == NULL )
00140        MCW_strncpy( dset->idcode.date , "None" , MCW_IDDATE ) ;
00141      else
00142        MCW_strncpy( dset->idcode.date , atr_str->ch , MCW_IDDATE ) ;
00143    }
00144 #endif
00145 
00146    ZERO_IDCODE(dset->anat_parent_idcode) ;
00147    ZERO_IDCODE(dset->warp_parent_idcode) ;
00148 
00149 #ifndef USE_APPLICATOR
00150    atr_str = THD_find_string_atr( blk , ATRNAME_IDANATPAR ) ;
00151    if( atr_str != NULL )
00152       MCW_strncpy( dset->anat_parent_idcode.str , atr_str->ch , MCW_IDSIZE ) ;
00153 
00154    atr_str = THD_find_string_atr( blk , ATRNAME_IDWARPPAR ) ;
00155    if( atr_str != NULL )
00156       MCW_strncpy( dset->warp_parent_idcode.str , atr_str->ch , MCW_IDSIZE ) ;
00157 #endif
00158 
00159    /*--------------------------------*/
00160    /*-- get data labels (optional) --*/
00161    /*--------------------------------*/
00162 
00163    atr_str = THD_find_string_atr( blk , ATRNAME_LABEL1 ) ;
00164    if( atr_str == NULL )
00165      atr_str = THD_find_string_atr( blk , ATRNAME_DATANAME ) ;
00166 
00167    if( atr_str != NULL ){
00168      MCW_strncpy( dset->label1 , atr_str->ch , THD_MAX_LABEL ) ;
00169    } else {
00170      MCW_strncpy( dset->label1 , THD_DEFAULT_LABEL , THD_MAX_LABEL ) ;
00171    }
00172 
00173    atr_str = THD_find_string_atr( blk , ATRNAME_LABEL2 ) ;
00174    if( atr_str != NULL ){
00175      MCW_strncpy( dset->label2 , atr_str->ch , THD_MAX_LABEL ) ;
00176    } else {
00177      MCW_strncpy( dset->label2 , THD_DEFAULT_LABEL , THD_MAX_LABEL ) ;
00178    }
00179 
00180    dset->keywords = NULL ;
00181 #ifndef USE_APPLICATOR
00182    atr_str = THD_find_string_atr( blk , ATRNAME_KEYWORDS ) ;
00183    if( atr_str != NULL )
00184       dset->keywords = XtNewString( atr_str->ch ) ;
00185 #endif
00186 
00187    /*---------------------------------*/
00188    /*-- get parent names (optional) --*/
00189    /*---------------------------------*/
00190 
00191    dset->anat_parent_name[0] = '\0' ;
00192    dset->warp_parent_name[0] = '\0' ;
00193    MCW_strncpy( dset->self_name , THD_DEFAULT_LABEL , THD_MAX_NAME ) ;
00194    dset->anat_parent = dset->warp_parent = NULL ;  /* must be set later */
00195 
00196 #ifndef USE_APPLICATOR
00197    atr_str = THD_find_string_atr( blk , ATRNAME_ANATOMY_PARENT ) ;
00198    if( atr_str != NULL && ISZERO_IDCODE(dset->anat_parent_idcode) ){
00199      MCW_strncpy( dset->anat_parent_name , atr_str->ch , THD_MAX_NAME ) ;
00200    }
00201 
00202    atr_str = THD_find_string_atr( blk , ATRNAME_WARP_PARENT ) ;
00203    if( atr_str != NULL && ISZERO_IDCODE(dset->warp_parent_idcode) ){
00204      MCW_strncpy( dset->warp_parent_name , atr_str->ch , THD_MAX_NAME ) ;
00205    }
00206 
00207    atr_str = THD_find_string_atr( blk , ATRNAME_DATANAME ) ;
00208    if( atr_str != NULL ){
00209      MCW_strncpy( dset->self_name , atr_str->ch , THD_MAX_NAME ) ;
00210    }
00211 #endif
00212 
00213    /*---------------------------*/
00214    /*-- find axes orientation --*/
00215    /*---------------------------*/
00216 
00217    daxes->type = DATAXES_TYPE ;
00218    daxes->nxx  = dkptr->dimsizes[0] ;
00219    daxes->nyy  = dkptr->dimsizes[1] ;
00220    daxes->nzz  = dkptr->dimsizes[2] ;
00221 
00222    atr_int = THD_find_int_atr( blk , ATRNAME_ORIENT_SPECIFIC ) ;
00223    if( atr_int == NULL ){
00224      DSET_ERR("illegal or missing ORIENT_SPECIFIC") ;
00225    } else {
00226      daxes->xxorient = atr_int->in[0] ;
00227      daxes->yyorient = atr_int->in[1] ;
00228      daxes->zzorient = atr_int->in[2] ;
00229    }
00230 
00231    /*----------------------*/
00232    /*-- find axes origin --*/
00233    /*----------------------*/
00234 
00235    atr_flo = THD_find_float_atr( blk , ATRNAME_ORIGIN ) ;
00236    if( atr_flo == NULL ){
00237      DSET_ERR("illegal or missing ORIGIN") ;
00238    } else {
00239      daxes->xxorg = atr_flo->fl[0] ;
00240      daxes->yyorg = atr_flo->fl[1] ;
00241      daxes->zzorg = atr_flo->fl[2] ;
00242    }
00243 
00244    /*------------------------*/
00245    /*-- find axes spacings --*/
00246    /*------------------------*/
00247 
00248    atr_flo = THD_find_float_atr( blk , ATRNAME_DELTA ) ;
00249    if( atr_flo == NULL ){
00250      DSET_ERR("illegal or missing DELTA") ;
00251    } else {
00252      daxes->xxdel = atr_flo->fl[0] ;
00253      daxes->yydel = atr_flo->fl[1] ;
00254      daxes->zzdel = atr_flo->fl[2] ;
00255    }
00256 
00257    /*---------------------------------------*/
00258    /*-- set bounding box for this dataset --*/
00259    /*---------------------------------------*/
00260 
00261    daxes->xxmin = daxes->xxorg ;
00262    daxes->xxmax = daxes->xxorg + (daxes->nxx-1) * daxes->xxdel ;
00263    if( daxes->xxmin > daxes->xxmax ){
00264      float temp   = daxes->xxmin ;
00265      daxes->xxmin = daxes->xxmax ; daxes->xxmax = temp ;
00266    }
00267 
00268    daxes->yymin = daxes->yyorg ;
00269    daxes->yymax = daxes->yyorg + (daxes->nyy-1) * daxes->yydel ;
00270    if( daxes->yymin > daxes->yymax ){
00271      float temp   = daxes->yymin ;
00272      daxes->yymin = daxes->yymax ; daxes->yymax = temp ;
00273    }
00274 
00275    daxes->zzmin = daxes->zzorg ;
00276    daxes->zzmax = daxes->zzorg + (daxes->nzz-1) * daxes->zzdel ;
00277    if( daxes->zzmin > daxes->zzmax ){
00278      float temp   = daxes->zzmin ;
00279      daxes->zzmin = daxes->zzmax ; daxes->zzmax = temp ;
00280    }
00281 
00282 #ifdef EXTEND_BBOX
00283    daxes->xxmin -= 0.5 * fabs(daxes->xxdel) ;  /* pushes edges back by 1/2  */
00284    daxes->xxmax += 0.5 * fabs(daxes->xxdel) ;  /* voxel dimensions (the box */
00285    daxes->yymin -= 0.5 * fabs(daxes->yydel) ;  /* defined above is based on */
00286    daxes->yymax += 0.5 * fabs(daxes->yydel) ;  /* voxel centers, not edges) */
00287    daxes->zzmin -= 0.5 * fabs(daxes->zzdel) ;
00288    daxes->zzmax += 0.5 * fabs(daxes->zzdel) ;
00289 #endif
00290 
00291    /*----------------------------------------------------------------*/
00292    /*--  matrix that transforms to Dicom (left-posterior-superior) --*/
00293    /*----------------------------------------------------------------*/
00294 
00295    /* At present, the code below just produces a permutation matrix.
00296       In the future, oblique scans may be allowed for by putting
00297       an arbitrary orthogonal matrix in here.  (A non orthogonal
00298       matrix implies non-orthogonal image scan axes and/or a
00299       different set of units than mm, neither of which I will allow!) */
00300 
00301    LOAD_ZERO_MAT(daxes->to_dicomm) ;
00302 
00303    switch( daxes->xxorient ){
00304       case ORI_R2L_TYPE:
00305       case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][0] = 1.0 ; break ;
00306       case ORI_P2A_TYPE:
00307       case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][0] = 1.0 ; break ;
00308       case ORI_I2S_TYPE:
00309       case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][0] = 1.0 ; break ;
00310 
00311       default: THD_FATAL_ERROR("illegal xxorient code") ;
00312    }
00313 
00314    switch( daxes->yyorient ){
00315       case ORI_R2L_TYPE:
00316       case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][1] = 1.0 ; break ;
00317       case ORI_P2A_TYPE:
00318       case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][1] = 1.0 ; break ;
00319       case ORI_I2S_TYPE:
00320       case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][1] = 1.0 ; break ;
00321 
00322       default: THD_FATAL_ERROR("illegal yyorient code") ;
00323    }
00324 
00325    switch( daxes->zzorient ){
00326       case ORI_R2L_TYPE:
00327       case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][2] = 1.0 ; break ;
00328       case ORI_P2A_TYPE:
00329       case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][2] = 1.0 ; break ;
00330       case ORI_I2S_TYPE:
00331       case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][2] = 1.0 ; break ;
00332 
00333       default: THD_FATAL_ERROR("illegal zxorient code") ;
00334    }
00335 
00336    /*------------------------------------*/
00337    /*-- read set of markers (optional) --*/
00338    /*------------------------------------*/
00339 
00340    dset->markers = NULL ;
00341 
00342 #ifndef USE_APPLICATOR
00343    atr_flo = THD_find_float_atr( blk , ATRNAME_MARKSXYZ ) ;
00344 
00345    if( atr_flo != NULL ){
00346       dset->markers = myXtNew( THD_marker_set ) ;  /* new set */
00347       ADDTO_KILL(dset->kl , dset->markers) ;
00348 
00349       /*-- copy floating coordinates into marker struct --*/
00350 
00351       COPY_INTO_STRUCT( *(dset->markers) ,  /* actual struct */
00352                         MARKS_FSTART ,      /* byte offset */
00353                         float ,             /* type being copied */
00354                         atr_flo->fl ,       /* start of source */
00355                         MARKS_FSIZE  ) ;    /* number of floats */
00356 
00357       /*----- must have labels along with coordinates -----*/
00358 
00359       atr_str = THD_find_string_atr( blk , ATRNAME_MARKSLAB ) ;
00360       if( atr_str == NULL ){
00361          DSET_ERR("MARKS_XYZ present but not MARKS_LAB!") ;
00362       } else {
00363          int im , llen ;
00364          THD_ivec3 iv ;
00365          float xxdown,xxup , yydown,yyup , zzdown,zzup ;
00366 
00367          /*-- copy labels into marker struct --*/
00368 
00369          COPY_INTO_STRUCT( *(dset->markers) ,
00370                            MARKS_LSTART ,
00371                            char ,
00372                            atr_str->ch ,
00373                            MARKS_LSIZE  ) ;
00374 
00375          /*-- check each marker for validity:
00376                 non-blank label string,
00377                 all coordinates inside bounding box --*/
00378 
00379          /** July 1995: extend bounding box a little, maybe **/
00380 
00381 #ifndef EXTEND_BBOX
00382          xxdown = daxes->xxmin - 0.501 * fabs(daxes->xxdel) ;
00383          xxup   = daxes->xxmax + 0.501 * fabs(daxes->xxdel) ;
00384          yydown = daxes->yymin - 0.501 * fabs(daxes->yydel) ;
00385          yyup   = daxes->yymax + 0.501 * fabs(daxes->yydel) ;
00386          zzdown = daxes->zzmin - 0.501 * fabs(daxes->zzdel) ;
00387          zzup   = daxes->zzmax + 0.501 * fabs(daxes->zzdel) ;
00388 #else
00389          xxdown = daxes->xxmin ;
00390          xxup   = daxes->xxmax ;
00391          yydown = daxes->yymin ;
00392          yyup   = daxes->yymax ;
00393          zzdown = daxes->zzmin ;
00394          zzup   = daxes->zzmax ;
00395 #endif
00396 
00397          dset->markers->numdef = dset->markers->numset = 0 ;
00398 
00399          for( im=0 ; im < MARKS_MAXNUM ; im++ ){
00400             llen = strlen( &(dset->markers->label[im][0]) ) ;
00401             dset->markers->valid[im]   =
00402                (llen > 0) &&
00403                ( dset->markers->xyz[im][0] >= xxdown ) &&
00404                ( dset->markers->xyz[im][0] <= xxup   ) &&
00405                ( dset->markers->xyz[im][1] >= yydown ) &&
00406                ( dset->markers->xyz[im][1] <= yyup   ) &&
00407                ( dset->markers->xyz[im][2] >= zzdown ) &&
00408                ( dset->markers->xyz[im][2] <= zzup   )    ;
00409 
00410             if( dset->markers->valid[im] ) (dset->markers->numset)++ ;
00411 
00412             if( llen > 0 ) (dset->markers->numdef)++ ;
00413 
00414             dset->markers->ovcolor[im] = -1 ;  /* default color */
00415 
00416          } /* end of loop over markers */
00417       } /* end of if marker labels exist */
00418 
00419       /*----- should also have help for each marker -----*/
00420 
00421       atr_str = THD_find_string_atr( blk , ATRNAME_MARKSHELP ) ;
00422       if( atr_str == NULL ){
00423          int im ;
00424          for( im=0 ; im < MARKS_MAXNUM ; im++ )
00425             dset->markers->help[im][0] = '\0' ;  /* empty string */
00426       } else {
00427          COPY_INTO_STRUCT( *(dset->markers) ,
00428                            MARKS_HSTART ,
00429                            char ,
00430                            atr_str->ch ,
00431                            MARKS_HSIZE  ) ;
00432       } /* end of if marker help exists */
00433 
00434       /*----- should also have action flags for the marker set -----*/
00435 
00436       atr_int = THD_find_int_atr( blk , ATRNAME_MARKSFLAG ) ;
00437       if( atr_int == NULL ){
00438          int im ;
00439          for( im=0 ; im < MARKS_MAXFLAG ; im++ )
00440             dset->markers->aflags[im] = -1 ;
00441       } else {
00442          COPY_INTO_STRUCT( *(dset->markers) ,
00443                            MARKS_ASTART ,
00444                            int ,
00445                            atr_int->in ,
00446                            MARKS_ASIZE  ) ;
00447          dset->markers->type = dset->markers->aflags[0] ;
00448       } /* end of if marker flags exist */
00449 
00450    } /* end of if markers exist */
00451 #endif
00452 
00453    /*--------------------------*/
00454    /*-- read warp (optional) --*/
00455    /*--------------------------*/
00456 
00457    dset->vox_warp  = NULL ;  /* 02 Nov 1996 */
00458    dset->self_warp = NULL ;  /* 26 Aug 2002 */
00459    dset->warp      = NULL ;
00460 
00461 #ifndef USE_APPLICATOR
00462    atr_int = THD_find_int_atr( blk , ATRNAME_WARP_TYPE ) ;
00463    if( atr_int != NULL ){  /* no warp */
00464       int wtype = atr_int->in[0] , rtype = atr_int->in[1]  ;
00465 
00466       dset->warp = myXtNew( THD_warp ) ;
00467       ADDTO_KILL( dset->kl , dset->warp ) ;
00468 
00469       atr_flo = THD_find_float_atr( blk , ATRNAME_WARP_DATA ) ;
00470       if( atr_flo == NULL ){
00471          DSET_ERR("illegal or missing WARP_DATA") ;
00472       } else {
00473          switch( wtype ){
00474 
00475             default: DSET_ERR("illegal WARP_TYPE warp code") ; break;
00476 
00477             case WARP_AFFINE_TYPE:{
00478                THD_affine_warp *ww = (THD_affine_warp *) dset->warp ;
00479                ww->type       = wtype ;
00480                ww->resam_type = rtype ;
00481                ww->warp.type  = MAPPING_LINEAR_TYPE ;
00482 
00483                COPY_INTO_STRUCT( ww->warp ,
00484                                  MAPPING_LINEAR_FSTART ,
00485                                  float ,
00486                                  atr_flo->fl ,
00487                                  MAPPING_LINEAR_FSIZE ) ;
00488             }
00489             break ;  /* end affine warp */
00490 
00491             case WARP_TALAIRACH_12_TYPE:{
00492                THD_talairach_12_warp *ww =
00493                   (THD_talairach_12_warp *) dset->warp ;
00494                int iw , ioff ;
00495                ww->type       = wtype ;
00496                ww->resam_type = rtype ;
00497                for( iw=0 ; iw < 12 ; iw++ ){
00498                   ww->warp[iw].type = MAPPING_LINEAR_TYPE ;
00499 
00500                   ioff = iw * MAPPING_LINEAR_FSIZE ;
00501 
00502                   COPY_INTO_STRUCT( ww->warp[iw] ,
00503                                     MAPPING_LINEAR_FSTART ,
00504                                     float ,
00505                                     &(atr_flo->fl[ioff]) ,
00506                                     MAPPING_LINEAR_FSIZE ) ;
00507 
00508                }  /* end loop over 12 warps */
00509             }
00510             break ;  /* end talairach_12 warp */
00511 
00512          } /* end of switch on warp type */
00513       } /* end of if on legal warp data */
00514    } /* end of if on warp existing */
00515 #endif
00516 
00517    /*----- read statistics, if available -----*/
00518 
00519 #ifndef USE_APPLICATOR
00520    atr_flo = THD_find_float_atr( blk , ATRNAME_BRICK_STATS ) ;  /* new style */
00521 
00522    if( atr_flo != NULL ){  /*** have new style statistics ***/
00523       int qq ;
00524       dset->stats         = myXtNew( THD_statistics ) ;
00525       dset->stats->type   = STATISTICS_TYPE ;
00526       dset->stats->parent = (XtPointer) dset ;
00527       dset->stats->nbstat = blk->nvals ;
00528       dset->stats->bstat  = (THD_brick_stats *)
00529                                XtMalloc( sizeof(THD_brick_stats) * blk->nvals ) ;
00530       for( qq=0 ; qq < blk->nvals ; qq++ ){
00531          if( 2*qq+1 < atr_flo->nfl ){
00532             dset->stats->bstat[qq].min = atr_flo->fl[2*qq] ;
00533             dset->stats->bstat[qq].max = atr_flo->fl[2*qq+1] ;
00534          } else {
00535             INVALIDATE_BSTAT( dset->stats->bstat[qq] ) ;
00536          }
00537       }
00538       ADDTO_KILL( dset->kl , dset->stats->bstat ) ;
00539       ADDTO_KILL( dset->kl , dset->stats ) ;
00540 
00541    } else {  /**** check for old style (version 1.03-4) statistics ****/
00542 
00543       atr_int = THD_find_int_atr( blk , ATRNAME_MINMAX ) ;
00544 
00545       if( atr_int == NULL ){  /*** no statistics at all ***/
00546          dset->stats = NULL ;
00547 
00548       } else {                /*** have old style (integer) statistics ***/
00549          int qq ;
00550          dset->stats         = myXtNew( THD_statistics ) ;
00551          dset->stats->type   = STATISTICS_TYPE ;
00552          dset->stats->parent = (XtPointer) dset ;
00553          dset->stats->nbstat = blk->nvals ;
00554          dset->stats->bstat  = (THD_brick_stats *)
00555                                   XtMalloc( sizeof(THD_brick_stats) * blk->nvals ) ;
00556          for( qq=0 ; qq < blk->nvals ; qq++ ){
00557             if( 2*qq+1 < atr_int->nin ){
00558                dset->stats->bstat[qq].min = (float) atr_int->in[2*qq] ;
00559                dset->stats->bstat[qq].max = (float) atr_int->in[2*qq+1] ;
00560             } else {
00561                INVALIDATE_BSTAT( dset->stats->bstat[qq] ) ;
00562             }
00563          }
00564          ADDTO_KILL( dset->kl , dset->stats->bstat ) ;
00565          ADDTO_KILL( dset->kl , dset->stats ) ;
00566       }
00567    }
00568 #endif
00569 
00570    /*--- read auxiliary statistics info, if any ---*/
00571 
00572    atr_flo = THD_find_float_atr( blk , ATRNAME_STAT_AUX ) ;
00573 
00574    if( atr_flo != NULL ){
00575      INIT_STAT_AUX( dset , atr_flo->nfl , atr_flo->fl ) ;
00576      iq = atr_flo->nfl ;
00577    } else {
00578      ZERO_STAT_AUX( dset ) ;
00579      iq = 0 ;
00580    }
00581 
00582    if( ISFUNC(dset) && FUNC_need_stat_aux[dset->func_type] > iq ){
00583      DSET_ERR("function type missing auxiliary statistical data") ;
00584    }
00585 
00586    /*--- read time-dependent information, if any ---*/
00587 
00588    atr_int = THD_find_int_atr  ( blk , ATRNAME_TAXIS_NUMS ) ;
00589    atr_flo = THD_find_float_atr( blk , ATRNAME_TAXIS_FLOATS ) ;
00590 
00591    if( atr_int != NULL && atr_flo != NULL ){
00592       int isfunc , nvals ;
00593 
00594       dset->taxis = myXtNew( THD_timeaxis ) ;
00595 
00596       dset->taxis->type    = TIMEAXIS_TYPE ;
00597       dset->taxis->ntt     = atr_int->in[0] ;
00598       dset->taxis->nsl     = atr_int->in[1] ;
00599       dset->taxis->ttorg   = atr_flo->fl[0] ;
00600       dset->taxis->ttdel   = atr_flo->fl[1] ;
00601       dset->taxis->ttdur   = atr_flo->fl[2] ;
00602       dset->taxis->zorg_sl = atr_flo->fl[3] ;
00603       dset->taxis->dz_sl   = atr_flo->fl[4] ;
00604 
00605       dset->taxis->units_type = atr_int->in[2] ;      /* 21 Oct 1996 */
00606       if( dset->taxis->units_type < 0 )               /* assign units */
00607          dset->taxis->units_type = UNITS_MSEC_TYPE ;  /* to the time axis */
00608 
00609       if( dset->taxis->nsl > 0 ){
00610          atr_flo = THD_find_float_atr( blk , ATRNAME_TAXIS_OFFSETS ) ;
00611          if( atr_flo == NULL || atr_flo->nfl < dset->taxis->nsl ){
00612             dset->taxis->nsl     = 0 ;
00613             dset->taxis->toff_sl = NULL ;
00614             dset->taxis->zorg_sl = 0.0 ;
00615             dset->taxis->dz_sl   = 0.0 ;
00616          } else {
00617             int ii ;
00618             dset->taxis->toff_sl = (float *) XtMalloc(sizeof(float)*dset->taxis->nsl) ;
00619             for( ii=0 ; ii < dset->taxis->nsl ; ii++ )
00620                dset->taxis->toff_sl[ii] = atr_flo->fl[ii] ;
00621          }
00622       } else {
00623          dset->taxis->nsl     = 0 ;
00624          dset->taxis->toff_sl = NULL ;
00625          dset->taxis->zorg_sl = 0.0 ;
00626          dset->taxis->dz_sl   = 0.0 ;
00627       }
00628 
00629       isfunc = ISFUNCTYPE(dset->type) ;
00630       nvals  = (isfunc) ? FUNC_nvals[dset->func_type]
00631                         : ANAT_nvals[dset->func_type]  ;
00632 
00633       if( nvals != 1 )
00634          DSET_ERR("Illegal time-dependent dataset and func_type combination!") ;
00635    }
00636 
00637    /*--- 23 Oct 1998: read the tagset information ---*/
00638 
00639 #ifndef USE_APPLICATOR
00640    atr_int = THD_find_int_atr   ( blk , ATRNAME_TAGSET_NUM    ) ;
00641    atr_flo = THD_find_float_atr ( blk , ATRNAME_TAGSET_FLOATS ) ;
00642    atr_str = THD_find_string_atr( blk , ATRNAME_TAGSET_LABELS ) ;
00643 
00644    if( atr_int != NULL && atr_flo != NULL && atr_str != NULL ){
00645       int nin=atr_int->nin , nfl=atr_flo->nfl , nch=atr_str->nch ;
00646       int ii , ntag , nfper , jj , kk ;
00647 
00648       ntag  = atr_int->in[0] ;  /* number of tags */
00649       nfper = atr_int->in[1] ;  /* number of floats per tag */
00650 
00651       if( ntag > MAX_TAG_NUM ) ntag = MAX_TAG_NUM ;
00652 
00653       dset->tagset = myXtNew( THD_usertaglist ) ;  /* create tagset */
00654       ADDTO_KILL( dset->kl , dset->tagset ) ;
00655 
00656       dset->tagset->num = ntag ;
00657       strcpy( dset->tagset->label , "Bebe Rebozo" ) ;  /* not used */
00658 
00659       /* read out tag values; allow for chance there isn't enough data */
00660 
00661 #undef  TF
00662 #define TF(i,j) ( ((j)<nfper && (i)*nfper+(j)<nfl) ? atr_flo->fl[(i)*nfper+(j)] : -666.0 )
00663       for( ii=0 ; ii < ntag ; ii++ ){
00664          dset->tagset->tag[ii].x   = TF(ii,0) ;  /* coords */
00665          dset->tagset->tag[ii].y   = TF(ii,1) ;
00666          dset->tagset->tag[ii].z   = TF(ii,2) ;
00667          dset->tagset->tag[ii].val = TF(ii,3) ;  /* value */
00668          dset->tagset->tag[ii].ti  = TF(ii,4) ;  /* time index; if < 0 ==> not set */
00669          if( dset->tagset->tag[ii].ti >= 0 ){
00670              dset->tagset->tag[ii].set = 1 ;
00671          } else {
00672              dset->tagset->tag[ii].set = 0 ; dset->tagset->tag[ii].ti = 0 ;
00673          }
00674       }
00675 #undef TF
00676 
00677       /* read out tag labels; allow for empty labels */
00678 
00679       jj = 0 ;
00680       for( ii=0 ; ii < ntag ; ii++ ){
00681          if( jj < nch ){
00682             kk = strlen( atr_str->ch + jj ) ;
00683             if( kk > 0 ) TAG_SETLABEL( dset->tagset->tag[ii] , atr_str->ch + jj ) ;
00684             else         sprintf( dset->tagset->tag[ii].label , "Tag %d" , ii+1 ) ;
00685             jj += kk+1 ;
00686          } else {
00687             sprintf( dset->tagset->tag[ii].label , "Tag %d" , ii+1 ) ;
00688          }
00689       }
00690    }
00691 #endif
00692 
00693    /* 10 May 2005: new function to apply some attributes
00694                    to dataset, rather than doing it here */
00695 
00696 #ifdef USE_APPLICATOR
00697    THD_datablock_apply_atr( dset ) ;
00698 #endif
00699 
00700    /*--- check for the following conditions:
00701            if warp exists,    warp_parent_name or _idcode must exist;
00702            if warp nonexists, warp_parent_name and _idcode must nonexist,
00703                               AND data must exist on disk                 ---*/
00704 
00705    if( dset->warp != NULL ){
00706      if( strlen(dset->warp_parent_name) <= 0 &&
00707          ISZERO_IDCODE(dset->warp_parent_idcode) )
00708        DSET_ERR("have warp but have no warp parent") ;
00709 
00710      dset->wod_flag = !allow_nodata && !DSET_ONDISK(dset) ;
00711    } else {
00712      if( strlen(dset->warp_parent_name) > 0 ||
00713          !ISZERO_IDCODE(dset->warp_parent_idcode) )
00714        DSET_ERR("have no warp but have warp parent") ;
00715 
00716      if( !allow_nodata && !DSET_ONDISK(dset) )
00717        DSET_ERR("have no warp but have no data on disk as well") ;
00718    }
00719 
00720    /* backup assignment of ID code if not assigned earlier */
00721 
00722    if( dset->idcode.str[0] == '\0' ) dset->idcode = MCW_new_idcode() ;
00723 
00724    /*--- that's all the work for now;
00725          if any error was flagged, kill this dataset and return nothing ---*/
00726 
00727    if( dset_ok == False ){
00728      fprintf(stderr,"PURGING dataset %s from memory\n",DSET_HEADNAME(dset)) ;
00729      THD_delete_3dim_dataset( dset , False ) ;
00730      RETURN(NULL) ;
00731    }
00732 
00733    /*--- If we assigned a new dataset idcode, write it back to disk ---*/
00734       /* (This code was for the old days, when there were datasets)
00735          (hanging around that hadn't yet been assigned ID codes.  ) */
00736 
00737 #if 0
00738    if( dset != NULL && new_idcode ){
00739      fprintf(stderr,"** Writing new ID code to dataset header %s\n",
00740              dset->dblk->diskptr->header_name ) ;
00741      THD_write_3dim_dataset( NULL , NULL , dset , False ) ;
00742    }
00743 #endif
00744 
00745    RETURN( dset );
00746 }

THD_fvec3 THD_3dind_to_3dmm THD_3dim_dataset  ,
THD_ivec3   
 

Definition at line 46 of file thd_coords.c.

References CURRENT_DAXES, THD_ivec3::ijk, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_brick_to_mri(), AFNI_ijk_to_xyz(), AFNI_marks_action_CB(), AFNI_set_viewpoint(), main(), SUMA_LoadPrepInVol(), THD_open_ctfmri(), and to_3dmm().

00048 {
00049    THD_dataxes * daxes ;
00050    THD_fvec3     fv ;
00051 
00052    daxes = CURRENT_DAXES(dset) ;
00053 
00054    fv.xyz[0] = daxes->xxorg + iv.ijk[0] * daxes->xxdel ;
00055    fv.xyz[1] = daxes->yyorg + iv.ijk[1] * daxes->yydel ;
00056    fv.xyz[2] = daxes->zzorg + iv.ijk[2] * daxes->zzdel ;
00057    return fv ;
00058 }

THD_fvec3 THD_3dind_to_3dmm_no_wod THD_3dim_dataset  ,
THD_ivec3   
 

Definition at line 62 of file thd_coords.c.

References THD_3dim_dataset::daxes, THD_ivec3::ijk, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by display_coords().

00064 {
00065    THD_dataxes * daxes ;
00066    THD_fvec3     fv ;
00067 
00068    daxes = dset->daxes ;
00069 
00070    fv.xyz[0] = daxes->xxorg + iv.ijk[0] * daxes->xxdel ;
00071    fv.xyz[1] = daxes->yyorg + iv.ijk[1] * daxes->yydel ;
00072    fv.xyz[2] = daxes->zzorg + iv.ijk[2] * daxes->zzdel ;
00073    return fv ;
00074 }

THD_ivec3 THD_3dind_to_fdind FD_brick  ,
THD_ivec3   
 

Definition at line 274 of file thd_coords.c.

References FD_brick::a123, abs, THD_ivec3::ijk, and FD_brick::sxyz.

Referenced by AFNI_brick_to_mri(), AFNI_overlay(), AFNI_seq_send_CB(), AFNI_set_valabel(), AFNI_set_viewpoint(), and main().

00275 {
00276    THD_ivec3 ib ;
00277    int qq , ax ;
00278 
00279    for( qq=0 ; qq < 3 ; qq++ ){
00280       ax = abs( br->a123.ijk[qq] ) - 1 ;
00281 
00282       if( br->a123.ijk[qq] > 0 ) ib.ijk[qq] = id.ijk[ax] ;
00283       else                       ib.ijk[qq] = br->sxyz.ijk[ax] - id.ijk[ax];
00284    }
00285 
00286    return ib ;
00287 }

THD_fvec3 THD_3dmm_to_3dfind THD_3dim_dataset  ,
THD_fvec3   
 

Definition at line 78 of file thd_coords.c.

References CURRENT_DAXES, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_brick_to_mri(), AFNI_make_voxwarp(), and main().

00080 {
00081    THD_dataxes * daxes ;
00082    THD_fvec3     iv ;
00083 
00084    daxes = CURRENT_DAXES(dset) ;
00085 
00086    iv.xyz[0] = (fv.xyz[0] - daxes->xxorg) / daxes->xxdel ;
00087    iv.xyz[1] = (fv.xyz[1] - daxes->yyorg) / daxes->yydel ;
00088    iv.xyz[2] = (fv.xyz[2] - daxes->zzorg) / daxes->zzdel ;
00089 
00090         if( iv.xyz[0] < 0            ) iv.xyz[0] = 0 ;
00091    else if( iv.xyz[0] > daxes->nxx-1 ) iv.xyz[0] = daxes->nxx-1 ;
00092 
00093         if( iv.xyz[1] <  0           ) iv.xyz[1] = 0 ;
00094    else if( iv.xyz[1] > daxes->nyy-1 ) iv.xyz[1] = daxes->nyy-1 ;
00095 
00096         if( iv.xyz[2] < 0            ) iv.xyz[2] = 0 ;
00097    else if( iv.xyz[2] > daxes->nzz-1 ) iv.xyz[2] = daxes->nzz-1 ;
00098 
00099    return iv ;
00100 }

THD_ivec3 THD_3dmm_to_3dind THD_3dim_dataset  ,
THD_fvec3   
 

Definition at line 104 of file thd_coords.c.

References CURRENT_DAXES, THD_ivec3::ijk, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_crosshair_label(), AFNI_initialize_view(), AFNI_jumpto_dicom(), AFNI_lock_carryout(), AFNI_marktog_CB(), AFNI_modify_viewing(), AFNI_overlay(), AFNI_setup_viewing(), AFNI_talto_CB(), AFNI_xyz_to_ijk(), EDIT_one_dataset(), from_3dmm(), insert_list(), main(), process_NIML_Node_ROI(), RCREND_xhair_overlay(), RCREND_xhair_underlay(), SUMA_Find_IminImax(), SUMA_Find_IminImax_Avg(), SUMA_FormAfnidset(), SUMA_make_vnlist(), THD_autonudge(), TT_whereami(), and xyz_to_ijk().

00106 {
00107    THD_dataxes * daxes ;
00108    THD_ivec3     iv ;
00109 
00110    daxes = CURRENT_DAXES(dset) ;
00111 
00112    iv.ijk[0] = (fv.xyz[0] - daxes->xxorg) / daxes->xxdel + 0.499 ;
00113    iv.ijk[1] = (fv.xyz[1] - daxes->yyorg) / daxes->yydel + 0.499 ;
00114    iv.ijk[2] = (fv.xyz[2] - daxes->zzorg) / daxes->zzdel + 0.499 ;
00115 
00116         if( iv.ijk[0] < 0            ) iv.ijk[0] = 0 ;
00117    else if( iv.ijk[0] > daxes->nxx-1 ) iv.ijk[0] = daxes->nxx-1 ;
00118 
00119         if( iv.ijk[1] < 0            ) iv.ijk[1] = 0 ;
00120    else if( iv.ijk[1] > daxes->nyy-1 ) iv.ijk[1] = daxes->nyy-1 ;
00121 
00122         if( iv.ijk[2] < 0            ) iv.ijk[2] = 0 ;
00123    else if( iv.ijk[2] > daxes->nzz-1 ) iv.ijk[2] = daxes->nzz-1 ;
00124 
00125    return iv ;
00126 }

THD_ivec3 THD_3dmm_to_3dind_no_wod THD_3dim_dataset  ,
THD_fvec3   
 

Definition at line 131 of file thd_coords.c.

References THD_3dim_dataset::daxes, THD_ivec3::ijk, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by segment_imarr().

00133 {
00134    THD_dataxes * daxes ;
00135    THD_ivec3     iv ;
00136 
00137    daxes = dset->daxes ;
00138 
00139    iv.ijk[0] = (fv.xyz[0] - daxes->xxorg) / daxes->xxdel + 0.499 ;
00140    iv.ijk[1] = (fv.xyz[1] - daxes->yyorg) / daxes->yydel + 0.499 ;
00141    iv.ijk[2] = (fv.xyz[2] - daxes->zzorg) / daxes->zzdel + 0.499 ;
00142 
00143         if( iv.ijk[0] < 0            ) iv.ijk[0] = 0 ;
00144    else if( iv.ijk[0] > daxes->nxx-1 ) iv.ijk[0] = daxes->nxx-1 ;
00145 
00146         if( iv.ijk[1] < 0            ) iv.ijk[1] = 0 ;
00147    else if( iv.ijk[1] > daxes->nyy-1 ) iv.ijk[1] = daxes->nyy-1 ;
00148 
00149         if( iv.ijk[2] < 0            ) iv.ijk[2] = 0 ;
00150    else if( iv.ijk[2] > daxes->nzz-1 ) iv.ijk[2] = daxes->nzz-1 ;
00151 
00152    return iv ;
00153 }

THD_fvec3 THD_3dmm_to_dicomm THD_3dim_dataset  ,
THD_fvec3   
 

Definition at line 163 of file thd_coords.c.

References THD_3dim_dataset::daxes, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, THD_FATAL_ERROR, THD_dataxes::xxorient, THD_fvec3::xyz, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by AFNI_brick_to_mri(), AFNI_dicomm_to_xyz(), AFNI_get_xhair_node(), AFNI_init_warp(), AFNI_make_warp(), AFNI_marks_quality_check(), AFNI_set_viewpoint(), AFNI_setup_viewing(), AFNI_xyz_to_dicomm(), brainnormalize_coord(), display_coords(), main(), PR_get_range(), SUMA_LoadPrepInVol(), THD_autonudge(), THD_cmass(), THD_dataset_center(), THD_dataset_info(), THD_dicomm_to_surefit(), THD_open_ctfmri(), THD_surefit_to_dicomm(), and to_3dmm().

00165 {
00166    THD_fvec3 dicv ;
00167    float xim,yim,zim , xdic,ydic,zdic ;
00168 
00169    xim = imv.xyz[0] ; yim = imv.xyz[1] ; zim = imv.xyz[2] ;
00170 
00171    switch( dset->daxes->xxorient ){
00172       case ORI_R2L_TYPE:
00173       case ORI_L2R_TYPE: xdic = xim ; break ;
00174       case ORI_P2A_TYPE:
00175       case ORI_A2P_TYPE: ydic = xim ; break ;
00176       case ORI_I2S_TYPE:
00177       case ORI_S2I_TYPE: zdic = xim ; break ;
00178 
00179       default: THD_FATAL_ERROR("illegal xxorient code") ;
00180    }
00181 
00182    switch( dset->daxes->yyorient ){
00183       case ORI_R2L_TYPE:
00184       case ORI_L2R_TYPE: xdic = yim ; break ;
00185       case ORI_P2A_TYPE:
00186       case ORI_A2P_TYPE: ydic = yim ; break ;
00187       case ORI_I2S_TYPE:
00188       case ORI_S2I_TYPE: zdic = yim ; break ;
00189 
00190       default: THD_FATAL_ERROR("illegal yyorient code") ;
00191    }
00192 
00193    switch( dset->daxes->zzorient ){
00194       case ORI_R2L_TYPE:
00195       case ORI_L2R_TYPE: xdic = zim ; break ;
00196       case ORI_P2A_TYPE:
00197       case ORI_A2P_TYPE: ydic = zim ; break ;
00198       case ORI_I2S_TYPE:
00199       case ORI_S2I_TYPE: zdic = zim ; break ;
00200 
00201       default: THD_FATAL_ERROR("illegal zzorient code") ;
00202    }
00203 
00204    dicv.xyz[0] = xdic ; dicv.xyz[1] = ydic ; dicv.xyz[2] = zdic ;
00205    return dicv ;
00206 }

void THD_3mni_to_3tta float *   ,
float *   ,
float *   
 

Definition at line 59 of file thd_mnicoords.c.

References LOAD_FVEC3, THD_mni_to_tta(), and THD_fvec3::xyz.

00060 {
00061    THD_fvec3 mv , tv ;
00062    LOAD_FVEC3( mv , *x,*y,*z ) ;
00063    tv = THD_mni_to_tta( mv ) ;
00064    *x = tv.xyz[0] ; *y = tv.xyz[1] ; *z = tv.xyz[2] ; return ;
00065 }

void THD_3tta_to_3mni float *   ,
float *   ,
float *   
 

Definition at line 51 of file thd_mnicoords.c.

References LOAD_FVEC3, THD_tta_to_mni(), and THD_fvec3::xyz.

Referenced by main().

00052 {
00053    THD_fvec3 mv , tv ;
00054    LOAD_FVEC3( tv , *x,*y,*z ) ;
00055    mv = THD_tta_to_mni( tv ) ;
00056    *x = mv.xyz[0] ; *y = mv.xyz[1] ; *z = mv.xyz[2] ; return ;
00057 }

int THD_add_bricks THD_3dim_dataset   dset,
void *    nini
 

Scan the NIML data or group element for sub-bricks to add to the given dataset.

  • Return value is number sub-bricks found (0 == something bad).
  • Note that the '<VOLUME_DATA ...>' elements don't have to contain the right amount of data for a sub-brick. If there is too little, the remaining voxels will be 0; if too much, the excess data is ignored.
  • Each column of data creates or replaces one sub-brick.
  • At the present time, the only datatypes allowed are: byte, short, float, complex (float pairs), and rgb (byte triples). Columns of other types will be ignored.
  • If a '<VOLUME_DATA ...>' element contains an 'index' attribute, then:
    • index >= 0 indicates which sub-brick the 1st column of the element goes into; subsequent columns go into successive sub-bricks, and any data already present in these sub-bricks will be over-written.
    • To indicate that the data is to be appended to the dataset, making new sub-bricks, just set index to a very large positive value (e.g., 9999999).
    • If 'index' is missing or negative, then the data columns will go into the first empty sub-bricks that are found; if none are found, new sub-bricks will be appended to the dataset.
  • If a '<VOLUME_DATA ...>' element contains a 'scale_factor' attribute, and the numerical value of factor is positive, this value is used to set the scale factor for all sub-bricks loaded from the element. Otherwise, any scale factor previously set will remain in effect.
  • Elements that are not named 'VOLUME_DATA' will be ignored here. -----------------------------------------------------------------------------

Definition at line 329 of file thd_nimlatr.c.

References AFNI_GOOD_DTYPE, calloc, DSET_ARRAY, DSET_CRUSH_BSTAT, DSET_NVALS, DSET_NVOX, EDIT_add_brick(), EDIT_BRICK_FACTOR, EDIT_substitute_brick(), ENTRY, ISVALID_DSET, mri_datum_size(), NI_element::name, NI_element_type(), NI_get_attribute(), NI_GROUP_TYPE, NI_group::part, NI_group::part_num, RETURN, STATUS, strtod(), tt, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.

Referenced by process_NIML_AFNI_dataset(), process_NIML_AFNI_volumedata(), and THD_niml_to_dataset().

00330 {
00331    int nbr=0 , tt=NI_element_type(nini) ;
00332    NI_element *nel ;
00333    int nxyz , ii , jj , nbar , vlen , kk , bb ;
00334    void *bar ;
00335    char *str ;
00336    float fac ;
00337 
00338 ENTRY("THD_add_bricks") ;
00339 
00340    if( !ISVALID_DSET(dset) || tt < 0 ) RETURN(0) ;
00341 
00342    /*-- if have a group element, do the parts by recursion --*/
00343 
00344    if( tt == NI_GROUP_TYPE ){
00345      NI_group *ngr = (NI_group *)nini ;
00346      int ip ;
00347      for( ip=0 ; ip < ngr->part_num ; ip++ )  /* loop over parts */
00348        nbr += THD_add_bricks( dset , ngr->part[ip] ) ;
00349      RETURN(nbr) ;
00350    }
00351 
00352    /*-- if here, have a single data element --*/
00353 
00354    nel = (NI_element *)nini ;
00355 
00356    /*- check element name to see if it's what we want -*/
00357 
00358    if( strcasecmp(nel->name,"VOLUME_DATA") != 0 ) RETURN(0) ;
00359 
00360    nxyz = DSET_NVOX(dset) ;   /* number of voxels in a sub-brick */
00361    vlen = nel->vec_len ;      /* number of values in a column of data */
00362    if( vlen > nxyz ) vlen = nxyz ;
00363 
00364    if( nel->vec_num < 1 || vlen < 1 ) RETURN(0) ;  /* no data at all? */
00365 
00366    /*- find index of sub-brick, if present -*/
00367 
00368    kk  = -1 ;                                 /* flag for overwrite */
00369                      str = NI_get_attribute( nel , "AFNI_index" ) ;
00370    if( str == NULL ) str = NI_get_attribute( nel , "index"      ) ;
00371    if( str != NULL && isdigit(*str) )
00372      kk = (int)strtol( str , NULL , 10 ) ;
00373 
00374    /*- and scale factor, if present -*/
00375 
00376    fac = 0.0 ;
00377                      str = NI_get_attribute( nel , "scale_factor" ) ;
00378    if( str == NULL ) str = NI_get_attribute( nel , "AFNI_factor"  ) ;
00379    if( str != NULL && ( *str== '-' || isdigit(*str) ) )
00380      fac = (float)strtod( str , NULL ) ;
00381 
00382    if(PRINT_TRACING){
00383      char str[256] ;
00384      sprintf(str,"kk=%d vlen=%d nxyz=%d fac=%f\n",kk,vlen,nxyz,fac);
00385      STATUS(str);
00386    }
00387 
00388    /*- loop over columns and enter them into the dataset -*/
00389 
00390    for( jj=0 ; jj < nel->vec_num ; jj++ ){
00391 
00392      if( !AFNI_GOOD_DTYPE(nel->vec_typ[jj]) ) continue ; /* skip this */
00393 
00394      /* create a volume array to hold this data */
00395 
00396      nbar = mri_datum_size(nel->vec_typ[jj]) ;   /* size of one value */
00397      bar = calloc( nbar , nxyz ) ;             /* will be zero filled */
00398      if( bar == NULL ) RETURN(nbr) ;               /* malloc failure! */
00399 
00400      /* copy data from element into this volume */
00401 
00402      memcpy( bar , nel->vec[jj] , vlen*nbar ) ;
00403 
00404      /* find a place (bb) to put this volume in the dataset */
00405 
00406      if( kk < 0 ){  /* scan for an empty sub-brick */
00407        for( ii=0 ; ii < DSET_NVALS(dset) ; ii++ )
00408          if( DSET_ARRAY(dset,ii) == NULL ) break ;
00409        if( ii == DSET_NVALS(dset) ) kk = ii ;  /* all full */
00410        bb = ii ;                               /* put here */
00411      } else if( kk > DSET_NVALS(dset) ){
00412        bb = DSET_NVALS(dset) ;                 /* at end */
00413      } else {
00414        bb = kk ;                               /* exactly here */
00415      }
00416 
00417      if( bb < DSET_NVALS(dset) ){   /* replace existing data */
00418        EDIT_substitute_brick( dset , bb , nel->vec_typ[jj] , bar ) ;
00419 
00420      } else {                       /* append new sub-brick */
00421        bb = DSET_NVALS(dset) ;
00422        EDIT_add_brick( dset , nel->vec_typ[jj] , 0.0 , bar ) ;
00423      }
00424      nbr++ ;   /* 1 more sub-brick! */
00425 
00426           if( fac >  0.0 ) EDIT_BRICK_FACTOR(dset,bb,fac) ;
00427      else if( fac <= 0.0 ) EDIT_BRICK_FACTOR(dset,bb,0.0) ;
00428 
00429      DSET_CRUSH_BSTAT(dset,bb) ;
00430 
00431      if( kk >= 0 ) kk++ ;  /* move to next sub-brick */
00432    }
00433 
00434    RETURN(nbr) ;
00435 }

void THD_allow_empty_dataset int   
 

Definition at line 13 of file thd_dsetdblk.c.

References allow_nodata.

Referenced by THD_fetch_dataset(), and THD_niml_to_dataset().

00013 { allow_nodata = n ; }

void THD_anonymize_dset THD_3dim_dataset   dset
 

Remove attributes from a dataset that might contain identifying strings. Can't help against sneaky users who put them into other places, but might be good enough for non-programmers. -------------------------------------------------------------------------

Definition at line 563 of file thd_atr.c.

References THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATRNAME_BRICK_KEYWORDS, ATRNAME_DATANAME, ATRNAME_KEYWORDS, ATRNAME_LABEL1, ATRNAME_LABEL2, THD_3dim_dataset::dblk, ENTRY, ISVALID_DATABLOCK, ISVALID_DSET, ATR_float::name, ATR_string::name, ATR_int::name, THD_datablock::natr, THD_erase_one_atr(), THD_set_string_atr, and ATR_any::type.

Referenced by THD_set_dataset_attributes().

00564 {
00565    THD_datablock *blk ;
00566    int ia ;
00567 
00568 ENTRY("THD_anonymize_dset") ;
00569 
00570    if( !ISVALID_DSET(dset) ) EXRETURN ;
00571    blk = dset->dblk ;
00572    if( !ISVALID_DATABLOCK(blk) || blk->natr <= 0 ) EXRETURN ;
00573 
00574    for( ia=0 ; ia < blk->natr ; ia++ ){
00575      char *aname ;
00576      ATR_any *next_atr = &(blk->atr[ia]) ;  /* pointer to this atr */
00577 
00578      switch( next_atr->type ){
00579 
00580        default: aname = NULL ; break ;
00581 
00582        case ATR_FLOAT_TYPE:{
00583          ATR_float *aa = (ATR_float *) next_atr ;
00584          aname = aa->name ;
00585        }
00586        break ;
00587 
00588        case ATR_STRING_TYPE:{
00589          ATR_string *aa = (ATR_string *) next_atr ;
00590          aname = aa->name ;
00591        }
00592        break ;
00593 
00594        case ATR_INT_TYPE:{
00595          ATR_int *aa = (ATR_int *) next_atr ;
00596          aname = aa->name ;
00597        }
00598        break ;
00599      }
00600 
00601      if( aname == NULL || *aname == '\0' ) continue ;
00602 
00603      if( strstr(aname,"NOTE") != NULL || strstr(aname,"_NAME") != NULL )
00604        THD_erase_one_atr( blk , aname ) ;
00605    }
00606 
00607    THD_set_string_atr( blk , ATRNAME_LABEL1         , "none" ) ;
00608    THD_set_string_atr( blk , ATRNAME_LABEL2         , "none" ) ;
00609    THD_set_string_atr( blk , ATRNAME_DATANAME       , "none" ) ;
00610    THD_erase_one_atr ( blk , ATRNAME_BRICK_KEYWORDS          ) ;
00611    THD_erase_one_atr ( blk , ATRNAME_KEYWORDS                ) ;
00612 
00613    EXRETURN ;
00614 }

void THD_anonymize_write int   
 

Definition at line 24 of file thd_dsetatr.c.

References anonymize.

Referenced by main().

00024 { anonymize = uu; }

void THD_append_datablock_keywords THD_datablock  ,
int   ,
char *   
 

Definition at line 178 of file thd_auxdata.c.

References THD_datablock::brick_keywords, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, THD_init_datablock_keywords(), THD_store_datablock_keywords(), and XtMalloc.

Referenced by EDIT_dset_items().

00179 {
00180    if( ! ISVALID_DATABLOCK(dblk)   ||
00181        iv < 0 || iv >= dblk->nvals || str == NULL ) return ;
00182 
00183    if( dblk->brick_keywords == NULL ) THD_init_datablock_keywords( dblk ) ;
00184 
00185    if( dblk->brick_keywords[iv] == NULL || dblk->brick_keywords[iv][0] == '\0' ){
00186       THD_store_datablock_keywords( dblk , iv , str ) ;
00187    } else if( str[0] != '\0' ){
00188       int ll = strlen(dblk->brick_keywords[iv]) + strlen(str) + 6 ;
00189       char *cc = (char*)XtMalloc( sizeof(char) * ll ) ;
00190       strcpy(cc,dblk->brick_keywords[iv]) ; strcat(cc," ; ") ; strcat(cc,str) ;
00191       myXtFree( dblk->brick_keywords[iv] ) ;
00192       dblk->brick_keywords[iv] = cc ;
00193    }
00194    return ;
00195 }

void THD_append_dataset_keywords THD_3dim_dataset  ,
char *   
 

Definition at line 285 of file thd_auxdata.c.

References ISVALID_3DIM_DATASET, THD_3dim_dataset::keywords, myXtFree, THD_store_dataset_keywords(), and XtMalloc.

Referenced by EDIT_dset_items().

00286 {
00287    if( ! ISVALID_3DIM_DATASET(dset) || str == NULL ) return ;
00288 
00289    if( dset->keywords == NULL || dset->keywords[0] == '\0' ){
00290       THD_store_dataset_keywords( dset , str ) ;
00291    } else if( str[0] != '\0' ){
00292       int ll = strlen(dset->keywords) + strlen(str) + 6 ;
00293       char *cc = (char*)XtMalloc( sizeof(char) * ll ) ;
00294       strcpy(cc,dset->keywords) ; strcat(cc," ; ") ; strcat(cc,str) ;
00295       myXtFree( dset->keywords ) ;
00296       dset->keywords = cc ;
00297    }
00298    return ;
00299 }

THD_3dim_dataset_array* THD_array_3dim_from_block THD_datablock_array   blk_arr
 

Definition at line 16 of file thd_manydset.c.

References ADDTO_3DARR, THD_3dim_dataset::anat_parent_name, THD_datablock_array::ar, THD_3dim_dataset_array::ar, DSET_ERR, DSET_WARN, ENTRY, FREE_3DARR, INIT_3DARR, ISANAT, ISFUNC, myXtFree, THD_datablock_array::num, THD_3dim_dataset_array::num, RETURN, SORT_3DARR, THD_3dim_from_block(), and THD_delete_3dim_dataset().

Referenced by THD_init_session().

00017 {
00018    THD_3dim_dataset_array * dset_arr ;
00019    THD_3dim_dataset *       dset ;
00020    int id ;
00021    Boolean dset_ok = True , all_anat , all_func ;
00022 
00023 ENTRY("THD_array_3dim_from_block") ;
00024 
00025    INIT_3DARR( dset_arr ) ;
00026 
00027    if( blk_arr == NULL || blk_arr->num <= 0 ) RETURN(dset_arr) ;
00028 
00029    for( id=0 ; id < blk_arr->num ; id++ ){
00030 
00031       dset = THD_3dim_from_block( blk_arr->ar[id] ) ;
00032 
00033       if( dset != NULL ) ADDTO_3DARR( dset_arr , dset ) ;
00034    }
00035 
00036    if( dset_arr->num <= 0 ) RETURN(dset_arr) ;
00037 
00038    /******************************************************/
00039    /*-- now, check the set of datasets for consistency --*/
00040    /******************************************************/
00041 
00042    /*-- 1.  Images should all be anatomy type or function type --*/
00043 
00044    all_anat = all_func = True ;
00045    for( id=0 ; id < dset_arr->num ; id++ ){
00046       dset      = dset_arr->ar[id] ;
00047       all_anat  = all_anat && ISANAT(dset) ;
00048       all_func  = all_func && ISFUNC(dset) ;
00049    }
00050    if( !all_anat && !all_func )
00051       DSET_ERR("image type conflicts (ANAT and FUNC mixed)") ;
00052 
00053    SORT_3DARR( dset_arr ) ;
00054 
00055    /*-- 2.  If all images are anat, nothing to do at this moment. --*/
00056 
00057    if( all_anat ){
00058    } /* end of dealing with all_anat case */
00059 
00060    /*-- 3.  If all images are func .... --*/
00061 
00062    if( all_func ){
00063       THD_3dim_dataset * dset0 ;
00064       int jd ;
00065 
00066 #if 0
00067       /* check for anat parents (should all have one) */
00068 
00069       for( id=0 ; id < dset_arr->num ; id++ ){  /* check for anat parent */
00070          dset = dset_arr->ar[id] ;
00071          if( strlen(dset->anat_parent_name) == 0 )
00072             DSET_WARN("functional image has no anatomical parent!") ;
00073       }
00074 #endif
00075 
00076    } /* end of dealing with all_func case */
00077 
00078    /*********************************************************/
00079    /*---------- if an error occurred, clean up -------------*/
00080    /*********************************************************/
00081 
00082    if( ! dset_ok ){
00083 
00084       /*-- delete data in subsidiary data structures --*/
00085 
00086       for( id=0 ; id < dset_arr->num ; id++ ){
00087          THD_delete_3dim_dataset( dset_arr->ar[id] , False ) ;
00088          myXtFree( dset_arr->ar[id] ) ;
00089       }
00090 
00091       FREE_3DARR( dset_arr ) ;
00092       INIT_3DARR( dset_arr ) ;  /* return a blank array */
00093    }
00094 
00095    /*-- at last!
00096         give the caller the list of (nearly) initialized datasets --*/
00097 
00098    RETURN(dset_arr) ;
00099 }

void THD_autobbox THD_3dim_dataset   dset,
int *    xm,
int *    xp,
int *    ym,
int *    yp,
int *    zm,
int *    zp
 

Find a bounding box for the main cluster of large-ish voxels. [xm..xp] will be box for x index, etc. -----------------------------------------------------------------------

Definition at line 704 of file thd_automask.c.

References ENTRY, MRI_autobbox(), MRI_FLOAT_PTR, mri_free(), MRI_IMAGE::nvox, THD_cliplevel(), and THD_median_brick().

Referenced by main().

00706 {
00707    MRI_IMAGE *medim ;
00708    float clip_val , *mar ;
00709    int nvox , ii ;
00710 
00711 ENTRY("THD_autobbox") ;
00712 
00713    medim = THD_median_brick(dset) ; if( medim == NULL ) EXRETURN ;
00714 
00715    mar  = MRI_FLOAT_PTR(medim) ;
00716    nvox = medim->nvox ;
00717    for( ii=0 ; ii < nvox ; ii++ ) mar[ii] = fabs(mar[ii]) ;
00718 
00719    clip_val = THD_cliplevel(medim,0.5) ;
00720    for( ii=0 ; ii < nvox ; ii++ )
00721      if( mar[ii] < clip_val ) mar[ii] = 0.0 ;
00722 
00723    MRI_autobbox( medim , xm,xp , ym,yp , zm,zp ) ;
00724 
00725    mri_free(medim) ; EXRETURN ;
00726 }

byte* THD_automask THD_3dim_dataset   dset
 

Make a byte mask for a 3D+time dataset -- 13 Aug 2001 - RWCox.

Definition at line 31 of file thd_automask.c.

References ENTRY, mmm, mri_automask_image(), mri_free(), RETURN, and THD_median_brick().

Referenced by main().

00032 {
00033    MRI_IMAGE *medim ;
00034    byte *mmm ;
00035 
00036 ENTRY("THD_automask") ;
00037 
00038    /* median at each voxel */
00039 
00040    medim = THD_median_brick(dset) ; if( medim == NULL ) RETURN(NULL);
00041 
00042    mmm = mri_automask_image( medim ) ;
00043 
00044    mri_free(medim) ; RETURN(mmm) ;
00045 }

void THD_automask_extclip int   
 

Definition at line 12 of file thd_automask.c.

References exterior_clip.

Referenced by main().

00012 { exterior_clip = e ; }

void THD_automask_verbose int   
 

Definition at line 9 of file thd_automask.c.

References v, and verb.

Referenced by main().

00009 { verb = v ; }

THD_fvec3 THD_autonudge THD_3dim_dataset   dsepi,
int    ivepi,
THD_3dim_dataset   dsant,
int    ivant,
float    step,
int    xstep,
int    ystep,
int    zstep,
int    code
 

Definition at line 13 of file thd_autonudge.c.

References AN, calloc, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_DX, DSET_DY, DSET_DZ, DSET_HEADNAME, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_unload, DSET_XORG, DSET_YORG, DSET_ZORG, DUMP_FVEC3, DUMP_IVEC3, EDIT_coerce_scale_type(), ENTRY, EP, EXIT, free, i, THD_ivec3::ijk, ISVALID_DSET, LOAD_FVEC3, malloc, MIN, mri_clear_data_pointer, mri_fix_data_pointer(), mri_free(), mri_new_vol_empty(), OV, RETURN, THD_3dfind_to_3dmm(), THD_3dmm_to_3dind(), THD_3dmm_to_dicomm(), THD_cliplevel(), THD_dicomm_to_3dmm(), UNLOAD_FVEC3, x2, THD_fvec3::xyz, y1, and z1.

Referenced by main().

00016 {
00017    THD_fvec3 fv1,fv2 , fvorg_old,fvorg_new , dxorg ;
00018    THD_ivec3 iv1,iv2 ;
00019    float *tar ;
00020    byte *epiar , *antar ;
00021    int ii,jj,kk , nxepi,nyepi,nzepi , nxyepi,nxyzepi ;
00022    int            nxant,nyant,nzant , nxyant,nxyzant ;
00023    MRI_IMAGE *tim ;
00024    float xorgepi , yorgepi , zorgepi , xx1,xx2,yy1,yy2,zz1,zz2 ;
00025    float epiclip , xorgant,yorgant,zorgant , f1,f2,g1,g2,h1,h2 , f,g,h ;
00026    float tx,ty,tz , dxepi,dyepi,dzepi , dxant,dyant,dzant , z1,z2,y1,y2,x1,x2 ;
00027    int *ov,*ovp , ovx=2*xstep+1 , ovy=2*ystep+1 , ovz=2*zstep+1 , ovxy=ovx*ovy ;
00028    int xant,yant,zant , pp,qq,rr , i,j,k , ip,jp,kp , ovtop , kstep ;
00029    float dxyz_ratio , vsum_thresh , vsum , sx,sy,sz ;
00030    int verb = ((code & 1) != 0) ;
00031 
00032    /*-- start the action! --*/
00033 
00034 ENTRY("THD_autonudge") ;
00035 
00036    /*-- sanity checks --*/
00037 
00038    if( !ISVALID_DSET(dsepi) ||
00039        !ISVALID_DSET(dsant) ||
00040        ivepi  < 0           || ivepi >= DSET_NVALS(dsepi) ||
00041        ivant < 0            || ivant >= DSET_NVALS(dsant) ||
00042        step <= 0.0 || ovx < 1 || ovy < 1 || ovz < 1 || ovx*ovy*ovz < 3 ){
00043 
00044       fprintf(stderr,"THD_autonudge: bad inputs!\n") ; EXIT(1) ;
00045    }
00046 
00047    /*-- load chosen sub-brick of epi into local float array --*/
00048 
00049    if( DSET_ARRAY(dsepi,ivepi) == NULL ){
00050      DSET_load(dsepi) ;
00051      if( !DSET_LOADED(dsepi) ){
00052         fprintf(stderr,"THD_autonudge: can't load %s\n",DSET_HEADNAME(dsepi));
00053         EXIT(1) ;
00054      }
00055    }
00056 
00057    nxepi = DSET_NX(dsepi) ;
00058    nyepi = DSET_NY(dsepi) ; nxyepi  = nxepi  * nyepi ;
00059    nzepi = DSET_NZ(dsepi) ; nxyzepi = nxyepi * nzepi ;
00060 
00061    tar = (float *) malloc( sizeof(float) * nxyzepi ) ;
00062    if( tar == NULL ){
00063       fprintf(stderr,"THD_autonudge: malloc failure for epiar\n"); EXIT(1);
00064    }
00065 
00066    EDIT_coerce_scale_type( nxyzepi ,
00067                            DSET_BRICK_FACTOR(dsepi,ivepi) ,
00068                            DSET_BRICK_TYPE(dsepi,ivepi) ,
00069                            DSET_ARRAY(dsepi,ivepi) , MRI_float , tar ) ;
00070    DSET_unload(dsepi) ;
00071 
00072    /*-- clip epi array values --*/
00073 
00074    tim = mri_new_vol_empty( nxepi , nyepi , nzepi , MRI_float ) ;
00075    mri_fix_data_pointer( tar , tim ) ;
00076    epiclip = THD_cliplevel( tim , 0.5 ) ;        /* get clip value */
00077    mri_clear_data_pointer(tim) ; mri_free(tim) ;
00078 
00079    if( epiclip <= 0.0 ){
00080       fprintf(stderr,"THD_autonudge: can't compute epiclip\n"); EXIT(1);
00081    }
00082 
00083    if( verb )
00084      fprintf(stderr,"THD_autonudge: epi clip level=%g\n",epiclip) ;
00085 
00086    epiar = (byte *) malloc(sizeof(byte)*nxyzepi) ;
00087    if( epiar == 0 ){
00088       fprintf(stderr,"THD_autonudge: malloc failed for epiar\n"); EXIT(1);
00089    }
00090 
00091    for( ii=0 ; ii < nxyzepi ; ii++ )      /* mask of supra-clip voxels */
00092       epiar[ii] = (tar[ii] > epiclip) ;
00093 
00094    free(tar) ;
00095 
00096    /*-- load chosen sub-brick of ant into local float array --*/
00097 
00098    if( DSET_ARRAY(dsant,ivant) == NULL ){
00099      DSET_load(dsant) ;
00100      if( !DSET_LOADED(dsant) ){
00101         fprintf(stderr,"THD_autonudge: can't load %s\n",DSET_HEADNAME(dsant));
00102         EXIT(1) ;
00103      }
00104    }
00105 
00106    nxant = DSET_NX(dsant) ;
00107    nyant = DSET_NY(dsant) ; nxyant  = nxant  * nyant ;
00108    nzant = DSET_NZ(dsant) ; nxyzant = nxyant * nzant ;
00109 
00110    tar = (float *) malloc( sizeof(float) * nxyzant ) ;
00111    if( tar == NULL ){
00112       fprintf(stderr,"THD_autonudge: malloc failure for antar\n"); EXIT(1);
00113    }
00114 
00115    EDIT_coerce_scale_type( nxyzant ,
00116                            DSET_BRICK_FACTOR(dsant,ivant) ,
00117                            DSET_BRICK_TYPE(dsant,ivant) ,
00118                            DSET_ARRAY(dsant,ivant) , MRI_float , tar ) ;
00119    DSET_unload(dsant) ;
00120 
00121    antar = (byte *) malloc(sizeof(byte)*nxyzant) ;
00122    if( antar == NULL ){
00123       fprintf(stderr,"THD_autonudge: malloc failure for antar\n"); EXIT(1);
00124    }
00125 
00126    for( ii=0 ; ii < nxyzant ; ii++ )  /* make mask */
00127       antar[ii] = (tar[ii] > 0.0) ;
00128 
00129    free(tar) ;
00130 
00131    /*-- find axis in ant that corresponds to x-axis in epi --*/
00132 
00133    LOAD_FVEC3(fv1,0,0,0) ;
00134    fv1 = THD_3dfind_to_3dmm( dsepi, fv1 ) ; /* coords in dsepi */
00135    fv1 = THD_3dmm_to_dicomm( dsepi, fv1 ) ; /* DICOM in dsepi  */
00136    fv1 = THD_dicomm_to_3dmm( dsant, fv1 ) ; /* coords in dsant */
00137    iv1 = THD_3dmm_to_3dind ( dsant, fv1 ) ; /* index in dsant  */
00138 
00139    LOAD_FVEC3(fv2,nxepi-1,0,0) ;
00140    fv2 = THD_3dfind_to_3dmm( dsepi , fv2 ) ; /* coords in dsepi */
00141    fv2 = THD_3dmm_to_dicomm( dsepi , fv2 ) ; /* DICOM in dsepi  */
00142    fv2 = THD_dicomm_to_3dmm( dsant, fv2 )  ; /* coords in dsant */
00143    iv2 = THD_3dmm_to_3dind ( dsant, fv2 )  ; /* index in dsant  */
00144 
00145         if( iv1.ijk[0] != iv2.ijk[0] ) xant = 0 ; /* epi x-axis */
00146    else if( iv1.ijk[1] != iv2.ijk[1] ) xant = 1 ; /* in ant    */
00147    else if( iv1.ijk[2] != iv2.ijk[2] ) xant = 2 ;
00148    else {
00149      fprintf(stderr,"THD_autonudge: incoherent x slicing?!\n");
00150      DUMP_IVEC3("iv1",iv1); DUMP_IVEC3("iv2",iv2); EXIT(1);
00151    }
00152 
00153    /*-- find axis in ant that corresponds to y-axis in epi --*/
00154 
00155    LOAD_FVEC3(fv2,0,nyepi-1,0) ;
00156    fv2 = THD_3dfind_to_3dmm( dsepi, fv2 ) ; /* coords in dsepi */
00157    fv2 = THD_3dmm_to_dicomm( dsepi, fv2 ) ; /* DICOM in dsepi  */
00158    fv2 = THD_dicomm_to_3dmm( dsant, fv2 ) ; /* coords in dsant */
00159    iv2 = THD_3dmm_to_3dind ( dsant, fv2 ) ; /* index in dsant  */
00160 
00161         if( iv1.ijk[0] != iv2.ijk[0] ) yant = 0 ; /* epi y-axis */
00162    else if( iv1.ijk[1] != iv2.ijk[1] ) yant = 1 ; /* in ant    */
00163    else if( iv1.ijk[2] != iv2.ijk[2] ) yant = 2 ;
00164    else {
00165      fprintf(stderr,"THD_autonudge: incoherent y slicing?!\n");
00166      DUMP_IVEC3("iv1",iv1); DUMP_IVEC3("iv2",iv2); EXIT(1);
00167    }
00168 
00169    /*-- find axis in ant that corresponds to z-axis in epi --*/
00170 
00171    LOAD_FVEC3(fv2,0,0,nzepi-1) ;
00172    fv2 = THD_3dfind_to_3dmm( dsepi, fv2 ) ; /* coords in dsepi */
00173    fv2 = THD_3dmm_to_dicomm( dsepi, fv2 ) ; /* DICOM in dsepi  */
00174    fv2 = THD_dicomm_to_3dmm( dsant, fv2 ) ; /* coords in dsant */
00175    iv2 = THD_3dmm_to_3dind ( dsant, fv2 ) ; /* index in dsant  */
00176 
00177         if( iv1.ijk[0] != iv2.ijk[0] ) zant = 0 ; /* epi z-axis */
00178    else if( iv1.ijk[1] != iv2.ijk[1] ) zant = 1 ; /* in ant    */
00179    else if( iv1.ijk[2] != iv2.ijk[2] ) zant = 2 ;
00180    else {
00181      fprintf(stderr,"THD_autonudge: incoherent z slicing?!\n");
00182      DUMP_IVEC3("iv1",iv1); DUMP_IVEC3("iv2",iv2); EXIT(1);
00183    }
00184 
00185 #if 0
00186    if( verb )
00187      fprintf(stderr,"  xant=%d yant=%d zant=%d\n",
00188              xant,yant,zant) ;
00189 #endif
00190 
00191    if( ((1<<xant) | (1<<yant) | (1<<zant)) != 7 ){
00192       fprintf(stderr,"THD_autonudge: incoherent xyz slicing!\n"
00193                      "               xant=%d yant=%d zant=%d\n",
00194               xant,yant,zant) ;
00195       EXIT(1) ;
00196    }
00197 
00198    /*-- allocate space for array of overlap counts --*/
00199 
00200    ov = (int *) calloc( sizeof(int) , ovx*ovy*ovz ) ;
00201    if( ov == NULL ){
00202       fprintf(stderr,"THD_autonudge: can't malloc space for overlap counts!\n");
00203       EXIT(1) ;
00204    }
00205 
00206    /*-- for each origin shift in the xant,yant directions,
00207         shift origin of ant dataset, then compare to epi dataset --*/
00208 
00209    xorgepi = DSET_XORG(dsepi) ; dxepi = DSET_DX(dsepi) ;
00210    yorgepi = DSET_YORG(dsepi) ; dyepi = DSET_DY(dsepi) ;
00211    zorgepi = DSET_ZORG(dsepi) ; dzepi = DSET_DZ(dsepi) ;
00212 
00213    xorgant = DSET_XORG(dsant) ; dxant = DSET_DX(dsant) ;
00214    yorgant = DSET_YORG(dsant) ; dyant = DSET_DY(dsant) ;
00215    zorgant = DSET_ZORG(dsant) ; dzant = DSET_DZ(dsant) ;
00216 
00217    dxyz_ratio  = fabs( (dxepi*dyepi*dzepi)/(dxant*dyant*dzant) ) ;
00218    vsum_thresh = 0.5*dxyz_ratio ;
00219 
00220    LOAD_FVEC3( fvorg_old,xorgant,yorgant,zorgant) ;
00221    LOAD_FVEC3( dxorg    ,dxant  ,dyant  ,dzant  ) ;
00222 
00223    ovtop = 0 ;
00224    if( nzepi < 11 ){
00225       kstep = 2 ;
00226    } else {
00227       kstep = (int)(0.2*nzepi+0.5) ;
00228    }
00229 
00230    for( pp=0 ; pp < ovx ; pp++ ){    /* loop over shifts in 3 directions */
00231     for( qq=0 ; qq < ovy ; qq++ ){
00232      for( rr=0 ; rr < ovz ; rr++ ){
00233 
00234      if( verb ) fprintf(stderr,"  starting shift %2d %2d %2d ",
00235                         pp-xstep,qq-ystep,rr-zstep) ;
00236 
00237      fvorg_new = fvorg_old ;   /* old ant origin */
00238 
00239      fvorg_new.xyz[xant] += (pp-xstep)*step*dxorg.xyz[xant]; /* shift epi-x */
00240      fvorg_new.xyz[yant] += (qq-ystep)*step*dxorg.xyz[yant]; /* shift epi-y */
00241      fvorg_new.xyz[zant] += (rr-zstep)*step*dxorg.xyz[zant]; /* shift epi-z */
00242 
00243      xorgant = fvorg_new.xyz[0] ;  /* load new ant origin */
00244      yorgant = fvorg_new.xyz[1] ;
00245      zorgant = fvorg_new.xyz[2] ;
00246 
00247      ovp = ov + (pp + qq*ovx + rr*ovxy) ; /* place to store result */
00248 
00249      /*-- foreach voxel in epi dataset,
00250           find how much of it is filled by nonzero ant voxels --*/
00251 
00252      for( kk=0 ; kk < nzepi ; kk++ ){
00253       z1 = zorgepi + dzepi*(kk-0.5) ; z2 = zorgepi + dzepi*(kk+0.49999) ;
00254 
00255       if( verb && kk%kstep == 0 ) fprintf(stderr,".") ;
00256 
00257       for( jj=0 ; jj < nyepi ; jj++ ){
00258        y1 = yorgepi + dyepi*(jj-0.5) ; y2 = yorgepi + dyepi*(jj+0.49999) ;
00259 
00260        for( ii=0 ; ii < nxepi ; ii++ ){
00261         if( EP(ii,jj,kk) == 0 ) continue ; /* skip voxel */
00262 
00263         x1 = xorgepi + dxepi*(ii-0.5) ; x2 = xorgepi + dxepi*(ii+0.49999) ;
00264 
00265         /* epi voxel covers coords [x1..x2] X [y1..y2] X [z1..z2] */
00266 
00267         /* transform these to ant dataset coords */
00268 
00269         LOAD_FVEC3(fv1,x1,y1,z1) ;                /* coords in epi  */
00270         fv1 = THD_3dmm_to_dicomm( dsepi, fv1 ) ;  /* DICOM coords   */
00271         fv1 = THD_dicomm_to_3dmm( dsant, fv1 ) ;  /* coords in ant */
00272         UNLOAD_FVEC3(fv1,xx1,yy1,zz1) ;
00273 
00274         LOAD_FVEC3(fv2,x2,y2,z2) ;                /* coords in epi  */
00275         fv2 = THD_3dmm_to_dicomm( dsepi, fv2 ) ;  /* DICOM coords   */
00276         fv2 = THD_dicomm_to_3dmm( dsant, fv2 ) ;  /* coords in ant */
00277         UNLOAD_FVEC3(fv2,xx2,yy2,zz2) ;
00278 
00279         /* epi voxel spans ant coords [xx1..xx2] X [yy1..yy2] X [zz1..zz2] */
00280 
00281         /* compute indices into ant dataset voxels */
00282 
00283         f1 = (xx1-xorgant)/dxant + 0.49999 ; f2 = (xx2-xorgant)/dxant + 0.49999 ;
00284         if( f1 > f2 ){ tx = f1 ; f1 = f2 ; f2 = tx ; }
00285         if( f1 >= nxant || f2 <= 0.0 ) continue ;
00286         if( f1 < 0.0 ) f1 = 0.0 ;  if( f2 >= nxant ) f2 = nxant - 0.001 ;
00287 
00288         g1 = (yy1-yorgant)/dyant + 0.49999 ; g2 = (yy2-yorgant)/dyant + 0.49999 ;
00289         if( g1 > g2 ){ ty = g1 ; g1 = g2 ; g2 = ty ; }
00290         if( g1 >= nyant || g2 <= 0.0 ) continue ;
00291         if( g1 < 0.0 ) g1 = 0.0 ;  if( g2 >= nyant ) g2 = nyant - 0.001 ;
00292 
00293         h1 = (zz1-zorgant)/dzant + 0.49999 ; h2 = (zz2-zorgant)/dzant + 0.49999 ;
00294         if( h1 > h2 ){ tz = h1 ; h1 = h2 ; h2 = tz ; }
00295         if( h1 >= nzant || h2 <= 0.0 ) continue ;
00296         if( h1 < 0.0 ) h1 = 0.0 ;  if( h2 >= nzant ) h2 = nzant - 0.001 ;
00297 
00298         /* epi voxel covers voxels [f1..f2] X [g1..g2] X [h1..h2] in ant */
00299 
00300         /* loop over these, and count how much is nonzero */
00301 
00302         vsum = 0.0 ;
00303         for( f=f1 ; f < f2 ; f = ip ){
00304          i = (int) f ; ip = i+1 ; tx = MIN(ip,f2) ; sx = tx - f ;
00305          for( g=g1 ; g < g2 ; g = jp ){
00306           j = (int) g ; jp = j+1 ; ty = MIN(jp,g2) ; sy = ty - g ;
00307           for( h=h1 ; h < h2 ; h = kp ){
00308              k = (int) h ; kp = k+1 ; tz = MIN(kp,h2) ; sz = tz - h ;
00309              if( AN(i,j,k) ) vsum += sx * sy * sz ;
00310         }}} /* end of loop over ant voxels */
00311 
00312 #if 0
00313 fprintf(stderr," epi=%d %d %d  ant=%6.2f..%6.2f %6.2f..%6.2f %6.2f..%6.2f vsum=%6.2f\n",
00314         ii,jj,kk , f1,f2 , g1,g2 , h1,h2 , vsum) ;
00315 #endif
00316 
00317         /* add to results for this shift */
00318 
00319         if( vsum > vsum_thresh ) (*ovp)++ ;
00320 
00321       }}} /* end of loop over epi voxels */
00322 
00323       if( verb ) fprintf(stderr," overlap=%d",*ovp) ;
00324       if( *ovp > ovtop ){
00325          ovtop = *ovp ; if( verb ) fprintf(stderr," *") ;
00326       }
00327       if( verb ) fprintf(stderr,"\n") ;
00328 
00329    }}} /* end of loop over shifts */
00330 
00331    /*-- find best shift in list --*/
00332 
00333    ii = jj = kk = ip = 0 ;
00334 
00335    for( pp=0 ; pp < ovx ; pp++ ){    /* loop over shifts in 3 directions */
00336     for( qq=0 ; qq < ovy ; qq++ ){
00337      for( rr=0 ; rr < ovz ; rr++ ){
00338         if( OV(pp,qq,rr) > ip ){
00339            ii = pp ; jj = qq ; kk = rr ; ip = OV(pp,qq,rr) ;
00340         }
00341    }}}
00342 
00343    fvorg_new.xyz[xant] = (ii-xstep)*step*dxorg.xyz[xant]; /* shift epi-x */
00344    fvorg_new.xyz[yant] = (jj-ystep)*step*dxorg.xyz[yant]; /* shift epi-y */
00345    fvorg_new.xyz[zant] = (kk-zstep)*step*dxorg.xyz[zant]; /* shift epi-z */
00346 
00347    if( verb ){
00348      fprintf(stderr," best shift: %d %d %d overlap=%d\n",
00349              ii-xstep,jj-ystep,kk-zstep,ip) ;
00350      DUMP_FVEC3(" best shift",fvorg_new) ;
00351    }
00352 
00353    free(ov) ; free(antar) ; free(epiar) ;
00354 
00355    RETURN( fvorg_new ) ;
00356 }

int THD_axcode THD_3dim_dataset  ,
char   
 

Definition at line 93 of file thd_rotangles.c.

References THD_3dim_dataset::daxes, ENTRY, ISVALID_DSET, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_R2L_TYPE, RETURN, THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by main(), mangle_angle(), NUD_finalize_dset_CB(), RT_registration_3D_setup(), THD_rotcom_to_matvec(), and VOLREG_main().

00094 {
00095    int xxor , yyor , zzor ;
00096 
00097 ENTRY("THD_axcode") ;
00098 
00099    if( ISVALID_DSET(dset) ){
00100       xxor = dset->daxes->xxorient ;
00101       yyor = dset->daxes->yyorient ;
00102       zzor = dset->daxes->zzorient ;
00103    } else {
00104       xxor = ORI_R2L_TYPE ;   /* 13 Feb 2001: Dicom order */
00105       yyor = ORI_A2P_TYPE ;
00106       zzor = ORI_I2S_TYPE ;
00107    }
00108    ori = toupper(ori) ;
00109    if( ori == ORIENT_tinystr[xxor][0] ) RETURN( 1) ;
00110    if( ori == ORIENT_tinystr[xxor][1] ) RETURN(-1) ;
00111    if( ori == ORIENT_tinystr[yyor][0] ) RETURN( 2) ;
00112    if( ori == ORIENT_tinystr[yyor][1] ) RETURN(-2) ;
00113    if( ori == ORIENT_tinystr[zzor][0] ) RETURN( 3) ;
00114    if( ori == ORIENT_tinystr[zzor][1] ) RETURN(-3) ;
00115    RETURN(-99) ;
00116 }

float THD_BN_dxyz void   
 

Definition at line 22 of file thd_brainormalize.c.

References thd_bn_dxyz.

00023 {
00024    return thd_bn_dxyz;
00025 }

int THD_BN_nx void   
 

Definition at line 26 of file thd_brainormalize.c.

References thd_bn_nx.

00027 {
00028    return thd_bn_nx;
00029 }

int THD_BN_ny void   
 

Definition at line 30 of file thd_brainormalize.c.

References thd_bn_ny.

00031 {
00032    return thd_bn_ny;
00033 }

int THD_BN_nz void   
 

Definition at line 34 of file thd_brainormalize.c.

References thd_bn_nz.

00035 {
00036    return thd_bn_nz;
00037 }

void THD_check_idcodes THD_sessionlist  
 

Definition at line 16 of file thd_checkidc.c.

References DSET_HEADNAME, THD_session::dsset, DUPLICATE_DSETS, ENTRY, FIRST_VIEW_TYPE, free, ISVALID_DSET, ISVALID_SESSIONLIST, LAST_VIEW_TYPE, malloc, THD_session::num_dsset, THD_sessionlist::num_sess, and THD_sessionlist::ssar.

Referenced by AFNI_read_inputs().

00017 {
00018    int iss , idd,jdd , ivv , dsnum , nd ;
00019    THD_session * sess ;
00020    THD_3dim_dataset * dset , ** dsl ;
00021 
00022 ENTRY("THD_check_idcodes") ;
00023 
00024    /*-- sanity check --*/
00025 
00026    if( ! ISVALID_SESSIONLIST(ssl) || ssl->num_sess <= 0 ) EXRETURN ;
00027 
00028    /*-- count number of datasets --*/
00029 
00030    for( dsnum=iss=0 ; iss < ssl->num_sess ; iss++ ){
00031       sess = ssl->ssar[iss] ;
00032       for( idd=0 ; idd < sess->num_dsset ; idd++ ){
00033          for( ivv=FIRST_VIEW_TYPE ; ivv <= LAST_VIEW_TYPE ; ivv++ ){
00034             dset = sess->dsset[idd][ivv] ;
00035             if( ISVALID_DSET(dset) ) dsnum++ ;
00036          }
00037       }
00038    }
00039 
00040    /*-- make list of datasets --*/
00041 
00042    dsl = (THD_3dim_dataset **) malloc( sizeof(THD_3dim_dataset *) * dsnum ) ;
00043 
00044    for( nd=iss=0 ; iss < ssl->num_sess ; iss++ ){
00045       sess = ssl->ssar[iss] ;
00046       for( idd=0 ; idd < sess->num_dsset ; idd++ ){
00047          for( ivv=FIRST_VIEW_TYPE ; ivv <= LAST_VIEW_TYPE ; ivv++ ){
00048             dset = sess->dsset[idd][ivv] ;
00049             if( ISVALID_DSET(dset) ) dsl[nd++] = dset ;
00050          }
00051       }
00052    }
00053 
00054    /*-- check list for duplicates --*/
00055 
00056    for( iss=idd=0 ; idd < dsnum-1 ; idd++ ){
00057      nd = 0 ;
00058      for( jdd=idd+1 ; jdd < dsnum ; jdd++ ){
00059        if( DUPLICATE_DSETS(dsl[idd],dsl[jdd]) ){ /* 20 Dec 2001: change EQUIV_IDCODES() to DUPLICATE_DSETS() */
00060          fprintf(stderr,
00061                  "\n*** WARNING: Identical ID codes in %s and %s",
00062                  DSET_HEADNAME(dsl[idd]) , DSET_HEADNAME(dsl[jdd]) ) ;
00063          iss++ ;
00064        }
00065      }
00066    }
00067 
00068    if( iss > 0 ) fprintf(stderr,"\n") ;
00069 
00070    free(dsl) ; EXRETURN ;
00071 }

float THD_cliplevel MRI_IMAGE  ,
float   
 

Definition at line 10 of file thd_cliplevel.c.

References calloc, ENTRY, free, MRI_IMAGE::kind, MRI_BYTE_PTR, mri_free(), mri_maxabs(), MRI_SHORT_PTR, mri_to_short(), MRI_IMAGE::nvox, and RETURN.

Referenced by main(), mri_automask_image(), mri_warp3D_align_setup(), THD_autobbox(), THD_autonudge(), THD_orient_guess(), and THD_outlier_count().

00011 {
00012    MRI_IMAGE *lim ;
00013    float fac , sfac=1.0 ;
00014    double dsum ;
00015    int nvox , *hist , ii,npos=0 , ncut,kk,ib , qq,nold ;
00016    short *sar ;
00017    byte  *bar ;
00018    int nhist , nneg=0 , nhalf ;
00019 
00020 ENTRY("THD_cliplevel") ;
00021    if( im == NULL ) RETURN(0.0) ;
00022 
00023    if( mfrac <= 0.0 || mfrac >= 0.99 ) mfrac = 0.50 ;
00024 
00025    /*-- allocate histogram --*/
00026 
00027    switch( im->kind ){
00028       case MRI_short: nhist = 32767 ; lim = im ; break ;
00029       case MRI_byte : nhist =   255 ; lim = im ; break ;
00030 
00031       default:
00032         fac = mri_maxabs(im) ; if( fac == 0.0 ) RETURN(0.0) ;
00033         sfac = 32767.0/fac ; nhist = 32767 ;
00034         lim = mri_to_short( sfac , im ) ;
00035       break ;
00036    }
00037 
00038    hist = (int *) calloc(sizeof(int),nhist+1) ;  /* 05 Nov 2001: +1 */
00039    nvox = im->nvox ;
00040 
00041    /*-- make histogram --*/
00042 
00043    dsum = 0.0 ;
00044    switch( lim->kind ){
00045       default: break ;
00046 
00047       case MRI_short:
00048          sar =  MRI_SHORT_PTR(lim) ;
00049          for( ii=0 ; ii < nvox ; ii++ ){
00050             if( sar[ii] > 0 && sar[ii] <= nhist ){
00051                hist[sar[ii]]++ ;
00052                dsum += (double)(sar[ii])*(double)(sar[ii]); npos++;
00053             } else if( sar[ii] < 0 )
00054               nneg++ ;
00055          }
00056       break ;
00057 
00058       case MRI_byte:                       /* there are no negative bytes */
00059          bar =  MRI_BYTE_PTR(lim) ;
00060          for( ii=0 ; ii < nvox ; ii++ ){
00061             if( bar[ii] > 0 ){
00062                hist[bar[ii]]++ ;
00063                dsum += (double)(bar[ii])*(double)(bar[ii]); npos++;
00064             }
00065          }
00066       break ;
00067    }
00068 
00069    if( npos <= 999 ){ free(hist); if(lim!=im)mri_free(lim); RETURN(0.0); }
00070 
00071    /*-- initialize cut position to include upper 65% of positive voxels --*/
00072 
00073    qq = 0.65 * npos ; ib = rint(0.5*sqrt(dsum/npos)) ;
00074    for( kk=0,ii=nhist-1 ; ii >= ib && kk < qq ; ii-- ) kk += hist[ii] ;
00075 
00076    /*-- algorithm --*/
00077 
00078    ncut = ii ; qq = 0 ;
00079    do{
00080       for( npos=0,ii=ncut ; ii < nhist ; ii++ ) npos += hist[ii] ; /* number >= cut */
00081       nhalf = npos/2 ;
00082       for( kk=0,ii=ncut ; ii < nhist && kk < nhalf ; ii++ )        /* find median */
00083          kk += hist[ii] ;
00084       nold = ncut ;
00085       ncut = mfrac * ii ;                                          /* new cut */
00086       qq++ ;
00087    } while( qq < 20 && ncut != nold ) ;
00088 
00089    free(hist) ; if( lim != im ) mri_free(lim) ;
00090 
00091    RETURN( (ncut/sfac) ) ;
00092 }

int thd_complexscan int   ,
complex  
 

Definition at line 40 of file thd_floatscan.c.

References cbuf, i, complex::i, IS_GOOD_FLOAT, r, and complex::r.

Referenced by T3D_read_images(), THD_load_analyze(), THD_load_datablock(), and THD_load_nifti().

00041 {
00042    int ii , nerr ;
00043 
00044    if( nbuf <= 0 || cbuf == NULL ) return 0 ;
00045 
00046    for( nerr=ii=0 ; ii < nbuf ; ii++ ){
00047       if( !IS_GOOD_FLOAT(cbuf[ii].r) ){ cbuf[ii].r = 0.0 ; nerr++ ; }
00048       if( !IS_GOOD_FLOAT(cbuf[ii].i) ){ cbuf[ii].i = 0.0 ; nerr++ ; }
00049    }
00050 
00051    return nerr ;
00052 }

void THD_const_detrend int   ,
float *   ,
float *   
 

Definition at line 11 of file thd_detrend.c.

00012 {
00013    int ii ; float xbar ;
00014 
00015    if( npt < 2 || xx == NULL ) return ;
00016 
00017    xbar = 0.0 ;
00018    for( ii=0 ; ii < npt ; ii++ ) xbar += xx[ii] ;
00019    xbar /= npt ;
00020    for( ii=0 ; ii < npt ; ii++ ) xx[ii] -= xbar ;
00021    if( xx0 != NULL ) *xx0 = xbar ;
00022    return ;
00023 }

void THD_coorder_fill char *   ,
THD_coorder  
 

Definition at line 323 of file thd_coords.c.

References THD_coorder::first, OR3OK, THD_coorder::orcode, ORCODE, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_R2L_TYPE, THD_coorder::second, THD_coorder::third, THD_coorder::xxor, THD_coorder::xxsign, THD_coorder::yyor, THD_coorder::yysign, THD_coorder::zzor, and THD_coorder::zzsign.

Referenced by AFNI_crosshair_pop_CB(), AFNI_parse_args(), CL_read_opts(), CORD_main(), ENV_coorder(), initialize_program(), main(), SUMA_Align_to_VolPar(), and SUMA_FormAfnidset().

00324 {
00325    char acod , orcode[4] ;
00326    int xx,yy,zz , ss1,ss2,ss3 , ii,ll ;
00327 
00328    if( cord == NULL ) return ;
00329 
00330    /* default values */
00331 
00332    cord->xxsign = cord->yysign = cord->zzsign = 1 ;
00333    cord->first  = 0 ;
00334    cord->second = 1 ;
00335    cord->third  = 2 ;
00336    cord->xxor   = ORI_R2L_TYPE ;
00337    cord->yyor   = ORI_A2P_TYPE ;
00338    cord->zzor   = ORI_I2S_TYPE ;
00339    strcpy(cord->orcode,"RAI") ;
00340 
00341    /* check string for OKness */
00342 
00343    if( in_orcode == NULL ) return ;
00344    strncpy(orcode,in_orcode,3) ; orcode[3] = '\0' ;
00345    ll = strlen(orcode) ; if( ll != 3 ) return ;
00346    for( ii=0 ; ii < 3 ; ii++ ) orcode[ii] = toupper(orcode[ii]) ;
00347    if( strncmp(orcode,"FLI",3) == 0 ) strcpy(orcode,"LPI") ;
00348 
00349    /* extract direction codes */
00350 
00351    acod = orcode[0] ; xx = ORCODE(acod) ;
00352    acod = orcode[1] ; yy = ORCODE(acod) ;
00353    acod = orcode[2] ; zz = ORCODE(acod) ;
00354 
00355    /* check direction codes for OKness */
00356 
00357    if( xx<0 || yy<0 || zz<0 || ! OR3OK(xx,yy,zz) ) return ;
00358 
00359    /* all is OK.  get signs of orientations */
00360 
00361    ss1 = (ORIENT_sign[xx] == '-') ? -1 : 1 ;
00362    ss2 = (ORIENT_sign[yy] == '-') ? -1 : 1 ;
00363    ss3 = (ORIENT_sign[zz] == '-') ? -1 : 1 ;
00364 
00365    /* whose on first? */
00366 
00367    cord->first  = xx / 2 ;
00368    cord->second = yy / 2 ;
00369    cord->third  = zz / 2 ;
00370 
00371    cord->xxsign = (cord->first ==0) ? ss1
00372                  :(cord->second==0) ? ss2 : ss3 ;
00373 
00374    cord->yysign = (cord->first ==1) ? ss1
00375                  :(cord->second==1) ? ss2 : ss3 ;
00376 
00377    cord->zzsign = (cord->first ==2) ? ss1
00378                  :(cord->second==2) ? ss2 : ss3 ;
00379 
00380    cord->xxor = xx ;
00381    cord->yyor = yy ;
00382    cord->zzor = zz ;
00383 
00384    strcpy(cord->orcode,orcode) ;
00385    return ;
00386 }

void THD_coorder_to_dicom THD_coorder  ,
float *   ,
float *   ,
float *   
 

Definition at line 423 of file thd_coords.c.

References THD_coorder::first, THD_coorder::second, THD_coorder::xxsign, THD_coorder::yysign, and THD_coorder::zzsign.

Referenced by AFNI_jumpto_CB(), from_3dmm(), main(), SUMA_Align_to_VolPar(), and SUMA_FormAfnidset().

00425 {
00426    float xval , yval , zval ;
00427 
00428    if( cord == NULL ) return ;
00429 
00430    /* unscramble order */
00431 
00432    xval = (cord->first  == 0) ? (*xx)
00433          :(cord->second == 0) ? (*yy) : (*zz) ;
00434 
00435    yval = (cord->first  == 1) ? (*xx)
00436          :(cord->second == 1) ? (*yy) : (*zz) ;
00437 
00438    zval = (cord->first  == 2) ? (*xx)
00439          :(cord->second == 2) ? (*yy) : (*zz) ;
00440 
00441    /* change signs */
00442 
00443    *xx = cord->xxsign * xval ;
00444    *yy = cord->yysign * yval ;
00445    *zz = cord->zzsign * zval ;
00446 
00447    return ;
00448 }

ATR_any* THD_copy_atr ATR_any   atr
 

Definition at line 618 of file thd_atr.c.

References ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, ENTRY, ATR_float::fl, ATR_int::in, ATR_float::name, ATR_string::name, ATR_int::name, ATR_string::nch, ATR_float::nfl, ATR_int::nin, RETURN, ATR_any::type, and XtMalloc.

Referenced by main().

00619 {
00620    ATR_any *atr_out=NULL ;
00621 
00622 ENTRY("THD_copy_atr") ;
00623 
00624    if( atr == NULL ) RETURN(NULL) ;
00625 
00626    switch( atr->type ){
00627 
00628      case ATR_FLOAT_TYPE:{
00629        ATR_float *aa = (ATR_float *)atr , *qq ;
00630        qq = (ATR_float *)XtMalloc(sizeof(ATR_float)) ;
00631        qq->type = ATR_FLOAT_TYPE ;
00632        qq->name = XtNewString( aa->name ) ;
00633        qq->nfl  = aa->nfl ;
00634        qq->fl   = (float *) XtMalloc( sizeof(float) * aa->nfl ) ;
00635        memcpy( qq->fl , aa->fl , sizeof(float) * aa->nfl ) ;
00636        atr_out = (ATR_any *)qq ;
00637      }
00638      break ;
00639 
00640      case ATR_STRING_TYPE:{
00641        ATR_string *aa = (ATR_string *)atr , *qq ;
00642        qq = (ATR_string *)XtMalloc(sizeof(ATR_string)) ;
00643        qq->type = ATR_STRING_TYPE ;
00644        qq->name = XtNewString( aa->name ) ;
00645        qq->nch  = aa->nch ;
00646        qq->ch   = (char *) XtMalloc( sizeof(char) * aa->nch ) ;
00647        memcpy( qq->ch , aa->ch , sizeof(char) * aa->nch ) ;
00648        atr_out = (ATR_any *)qq ;
00649      }
00650      break ;
00651 
00652      case ATR_INT_TYPE:{
00653        ATR_int *aa = (ATR_int *)atr , *qq ;
00654        qq = (ATR_int *)XtMalloc(sizeof(ATR_int)) ;
00655        qq->type = ATR_INT_TYPE ;
00656        qq->name = XtNewString( aa->name ) ;
00657        qq->nin  = aa->nin ;
00658        qq->in   = (int *) XtMalloc( sizeof(int) * aa->nin ) ;
00659        memcpy( qq->in , aa->in , sizeof(int) * aa->nin ) ;
00660        atr_out = (ATR_any *)qq ;
00661      }
00662      break ;
00663    }
00664 
00665    RETURN(atr_out) ;
00666 }

void THD_copy_datablock_auxdata THD_datablock  ,
THD_datablock  
 

Definition at line 18 of file thd_auxdata.c.

References THD_datablock::brick_keywords, THD_datablock::brick_lab, THD_datablock::brick_stataux, THD_datablock::brick_statcode, DQQ, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, THD_init_datablock_keywords(), THD_init_datablock_labels(), THD_init_datablock_stataux(), THD_store_datablock_keywords(), THD_store_datablock_label(), and THD_store_datablock_stataux().

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), EDIT_dset_items(), EDIT_empty_copy(), main(), and THD_warp3D().

00019 {
00020    int new_nvals , old_nvals , min_nvals , iv,kv , ibr ;
00021 
00022 DQQ("entry") ;
00023 
00024    if( ! ISVALID_DATABLOCK(new_dblk) ) return ;
00025 
00026    new_nvals = new_dblk->nvals ;
00027 
00028    if( new_dblk->brick_lab != NULL ){
00029       for( ibr=0 ; ibr < new_nvals ; ibr++ ) myXtFree( new_dblk->brick_lab[ibr] ) ;
00030       myXtFree( new_dblk->brick_lab ) ;
00031    }
00032 
00033    if( new_dblk->brick_keywords != NULL ){
00034       for( ibr=0 ; ibr < new_nvals ; ibr++ ) myXtFree( new_dblk->brick_keywords[ibr] ) ;
00035       myXtFree( new_dblk->brick_keywords ) ;
00036    }
00037 
00038    if( new_dblk->brick_statcode != NULL )
00039       myXtFree( new_dblk->brick_statcode ) ;
00040 
00041    if( new_dblk->brick_stataux != NULL ){
00042       for( ibr=0 ; ibr < new_nvals ; ibr++ ) myXtFree( new_dblk->brick_stataux[ibr] ) ;
00043       myXtFree( new_dblk->brick_stataux ) ;
00044    }
00045 
00046    new_dblk->brick_lab      = NULL ;
00047    new_dblk->brick_keywords = NULL ;
00048    new_dblk->brick_statcode = NULL ;
00049    new_dblk->brick_stataux  = NULL ;
00050 
00051 DQQ("finish nulling") ;
00052 
00053    if( ! ISVALID_DATABLOCK(old_dblk) ) return ;
00054 
00055    old_nvals = old_dblk->nvals ;
00056    min_nvals = (old_nvals < new_nvals) ? old_nvals : new_nvals ;
00057 
00058 DQQ("starting copy") ;
00059 
00060    if( old_dblk->brick_lab != NULL ){
00061 DQQ("copy labels") ;
00062       THD_init_datablock_labels( new_dblk ) ;
00063       for( iv=0 ; iv < min_nvals ; iv++ )
00064          THD_store_datablock_label( new_dblk , iv , old_dblk->brick_lab[iv] ) ;
00065    }
00066 
00067    if( old_dblk->brick_keywords != NULL ){
00068 DQQ("copy keywords") ;
00069       THD_init_datablock_keywords( new_dblk ) ;
00070       for( iv=0 ; iv < min_nvals ; iv++ )
00071          THD_store_datablock_keywords( new_dblk , iv , old_dblk->brick_keywords[iv] ) ;
00072    }
00073 
00074    if( old_dblk->brick_statcode != NULL ){
00075 DQQ("copy statcode and stataux") ;
00076       THD_init_datablock_stataux( new_dblk ) ;
00077       for( iv=0 ; iv < min_nvals ; iv++ ){
00078          kv = old_dblk->brick_statcode[iv] ;
00079          THD_store_datablock_stataux( new_dblk , iv , kv ,
00080                                       FUNC_need_stat_aux[kv] ,
00081                                       old_dblk->brick_stataux[iv] ) ;
00082       }
00083    }
00084 
00085 DQQ("exit") ;
00086    return ;
00087 }

THD_3dim_dataset* THD_copy_dset_subs THD_3dim_dataset  ,
int *   
 

Definition at line 471 of file thd_mastery.c.

References ADDTO_KILL, THD_diskptr::byte_order, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_ARRAY, DSET_BRICK_TYPE, DSET_delete, DSET_load, DSET_LOADED, EDIT_empty_copy(), EDIT_substitute_brick(), ENTRY, IDENTITY_WARP, THD_3dim_dataset::kl, malloc, THD_datablock::malloc_type, mri_datum_size(), mri_short_order(), myXtNew, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, RETURN, STORAGE_BY_BRICK, THD_diskptr::storage_mode, THD_setup_mastery(), THD_3dim_dataset::warp, and THD_3dim_dataset::wod_flag.

Referenced by r_new_resam_dset().

00472 {
00473     THD_3dim_dataset * dout;
00474     MRI_TYPE           kind;
00475     char             * newdata;
00476     int                sub, subs;
00477     int                dsize, nxyz, rv;
00478 
00479 ENTRY("THD_copy_dset_subs");
00480 
00481     /* validate inputs */
00482     if ( !din || !dlist )
00483     {
00484         fprintf(stderr, "** THD_copy_dset_subs: bad input (%p,%p)\n",
00485                 din,dlist);
00486         RETURN(NULL);
00487     }
00488 
00489     if ( dlist[0] <= 0 )
00490     {
00491         fprintf(stderr,"** THD_copy_dset_subs: invalid dlist length %d\n",
00492                 dlist[0]);
00493         RETURN(NULL);
00494     }
00495 
00496     dout = EDIT_empty_copy(din);
00497     rv = THD_setup_mastery(dout, dlist);
00498     if ( rv != 0 )
00499     {
00500         fprintf(stderr, "** failure: THD_setup_mastery() returned %d\n", rv);
00501         RETURN(NULL);
00502     }
00503 
00504     /* be sure that we have some data to copy */
00505     DSET_load(din);
00506     if ( ! DSET_LOADED(din) )
00507     {
00508         fprintf(stderr,"** THD_copy_dset_subs: cannot load input dataset\n");
00509         RETURN(NULL);
00510     }
00511 
00512     /* a basic warp is needed if header is written out - PLUTO_add_dset() */
00513     dout->warp  = myXtNew( THD_warp );
00514     *dout->warp = IDENTITY_WARP;
00515     ADDTO_KILL( dout->kl, dout->warp );
00516 
00517     dout->dblk->diskptr->byte_order   = mri_short_order();
00518     dout->dblk->diskptr->storage_mode = STORAGE_BY_BRICK;
00519 
00520     /* now copy all of the sub-bricks */
00521     nxyz = dout->daxes->nxx * dout->daxes->nyy * dout->daxes->nzz;
00522     subs = dlist[0];
00523     for ( sub = 0; sub < subs; sub++ )
00524     {
00525         kind = DSET_BRICK_TYPE(dout, sub);
00526         dsize = mri_datum_size( kind );
00527         if ( (newdata = (char *)malloc( nxyz * dsize )) == NULL )
00528         {
00529             fprintf( stderr, "r frdb: alloc failure: %d bytes!\n",
00530                      nxyz * dsize );
00531             DSET_delete(dout);
00532             RETURN(NULL);
00533         }
00534 
00535         memcpy(newdata,DSET_ARRAY(din,dlist[sub+1]), nxyz*dsize);
00536         EDIT_substitute_brick(dout, sub, kind, (void *)newdata);
00537     }
00538 
00539     dout->dblk->malloc_type = DATABLOCK_MEM_MALLOC;
00540     dout->wod_flag = False;             /* since data is now in memory */
00541 
00542     RETURN(dout);
00543 }

int THD_count_databricks THD_datablock   dblk
 

Definition at line 20 of file thd_countb.c.

References THD_datablock::brick, DBLK_ARRAY, DBLK_BRICK, ISVALID_DATABLOCK, and THD_datablock::nvals.

Referenced by AFNI_fimmer_compute(), EDIT_dset_items(), fim3d_fimmer_compute(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), PLUTO_4D_to_nothing(), THD_alloc_datablock(), THD_delete_datablock(), THD_load_datablock(), THD_load_statistics(), THD_setup_mastery(), THD_update_statistics(), and THD_write_datablock().

00021 {
00022    int ibr , count ;
00023 
00024    if( ! ISVALID_DATABLOCK(dblk) || dblk->brick == NULL ) return -1 ;
00025 
00026    count = 0 ;
00027    for( ibr=0 ; ibr < dblk->nvals ; ibr++ )
00028       if( DBLK_BRICK(dblk,ibr) != NULL && DBLK_ARRAY(dblk,ibr) != NULL )
00029         count++ ;
00030 
00031    return count ;
00032 }

int THD_countmask int    nvox,
byte   mmm
 

Count the number of nonzero voxels in a mask. -----------------------------------------------------------------------

Definition at line 103 of file thd_makemask.c.

References mc, and mmm.

Referenced by BFIT_prepare_dataset(), CORREL_main(), get_cmask(), HISTO_main(), init_floatvector_array(), main(), MRG_read_opts(), mri_medianfilter(), read_input_data(), SCAT_main(), SUMA_FormAfnidset(), SUMA_Get_isosurface_datasets(), THD_orient_guess(), UC_read_opts(), and validate_datasets().

00104 {
00105    int ii,mc ;
00106 
00107    if( nvox <= 0 || mmm == NULL ) return 0 ;
00108 
00109    for( ii=mc=0 ; ii < nvox ; ii++ ) if( mmm[ii] ) mc++ ;
00110 
00111    return mc ;
00112 }

void THD_cubic_detrend int    npt,
float *    far
 

Cubic detrend a float array in place.

Definition at line 134 of file thd_detrend.c.

References far.

00135 {
00136    register int ii ;
00137    float g0,g1,g2,g3 , f0,f1,f2,f3 , t1,t2,t5,t8 , t95,t56,t22,t25,txx ;
00138 
00139    if( npt < 5 || far == NULL ) return ;
00140 
00141    t8 = npt*npt ; t2 = npt-1.0 ; t5 = t2*(npt-2.0) ;
00142    t95 = 0.05*t5*(npt-3.0) ;
00143    t56 = 0.16666667*t5 ;
00144    t22 = 0.5*t2 ;
00145    t25 = 1.5*t2 ;
00146    txx = 0.6*t8-1.5*npt+1.1 ;
00147 
00148    g0=g1=g2=g3=0.0 ;
00149    for( ii=0 ; ii < npt ; ii++ ){
00150       t1 = ii*ii ;
00151       f1 = ii - t22 ;
00152       f2 = t1 - t2*ii + t56 ;
00153       f3 = t1*(ii - t25) + txx*ii - t95 ;
00154 
00155       g0 += far[ii] ;
00156       g1 += far[ii] * f1 ;
00157       g2 += far[ii] * f2 ;
00158       g3 += far[ii] * f3 ;
00159    }
00160    g0 *= (1.0/npt) ;
00161    g1 *= 12.0/(npt*(t8-1.0)) ;
00162    g2 *= 180.0/(npt*(t8-1.0)*(t8-4.0)) ;
00163    g3 *= 2800.0/(npt*(t8-1.0)*(t8-4.0)*(t8-9.0)) ;
00164 
00165    for( ii=0 ; ii < npt ; ii++ ){
00166       t1 = ii*ii ;
00167       f1 = ii- t22 ;
00168       f2 = t1 - t2*ii + t56 ;
00169       f3 = t1*(ii - t25) + txx*ii - t95 ;
00170 
00171       far[ii] -= ( g0 + g1*f1 + g2*f2 + g3*f3 ) ;
00172    }
00173 
00174    return ;
00175 }

int THD_cwd char *    pathname
 

Change working directory.

Definition at line 37 of file thd_filestuff.c.

00038 {
00039    if( pathname == NULL || *pathname == '\0' ) return 0 ;
00040    return ( chdir(pathname) == 0 ) ;
00041 }

void THD_datablock_apply_atr THD_3dim_dataset   dset
 

Apply attributes to modify an existing datablock. Only some attributes have an effect. 09 May 2005 -- written to support NIfTI-ization, by allowing attributes to be applied AFTER a dataset is created. -----------------------------------------------------------------------------

Definition at line 441 of file thd_initdblk.c.

References ADDTO_KILL, THD_marker_set::aflags, THD_3dim_dataset::anat_parent_idcode, THD_3dim_dataset::anat_parent_name, ATR_IS_FLT, ATR_IS_INT, ATR_IS_STR, ATRNAME_ANATOMY_PARENT, ATRNAME_BRICK_KEYWORDS, ATRNAME_BRICK_LABS, ATRNAME_BRICK_STATAUX, ATRNAME_BRICK_STATS, ATRNAME_DATANAME, ATRNAME_IDANATPAR, ATRNAME_IDDATE, ATRNAME_IDSTRING, ATRNAME_IDWARPPAR, ATRNAME_KEYWORDS, ATRNAME_MARKSFLAG, ATRNAME_MARKSHELP, ATRNAME_MARKSLAB, ATRNAME_MARKSXYZ, ATRNAME_TAGSET_FLOATS, ATRNAME_TAGSET_LABELS, ATRNAME_TAGSET_NUM, ATRNAME_WARP_DATA, ATRNAME_WARP_PARENT, ATRNAME_WARP_TYPE, THD_datablock::brick_keywords, THD_datablock::brick_lab, THD_statistics::bstat, ATR_string::ch, COPY_INTO_STRUCT, MCW_idcode::date, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, ENTRY, ATR_float::fl, THD_marker_set::help, THD_3dim_dataset::idcode, ATR_int::in, INVALIDATE_BSTAT, ISVALID_DSET, ISZERO_IDCODE, THD_3dim_dataset::keywords, THD_3dim_dataset::kl, THD_marker_set::label, THD_usertaglist::label, THD_usertag::label, MAPPING_LINEAR_FSIZE, MAPPING_LINEAR_FSTART, MAPPING_LINEAR_TYPE, THD_3dim_dataset::markers, MARKS_ASIZE, MARKS_ASTART, MARKS_FSIZE, MARKS_FSTART, MARKS_HSIZE, MARKS_HSTART, MARKS_LSIZE, MARKS_LSTART, MARKS_MAXFLAG, MARKS_MAXNUM, THD_brick_stats::max, MAX_TAG_NUM, MCW_IDDATE, MCW_IDSIZE, MCW_strncpy, THD_brick_stats::min, myXtNew, THD_statistics::nbstat, ATR_string::nch, ATR_float::nfl, ATR_int::nin, THD_usertaglist::num, THD_marker_set::numdef, THD_marker_set::numset, THD_datablock::nvals, nz, THD_marker_set::ovcolor, THD_statistics::parent, THD_affine_warp::resam_type, THD_talairach_12_warp::resam_type, THD_3dim_dataset::self_name, THD_usertag::set, STATISTICS_TYPE, THD_3dim_dataset::stats, STATUS, MCW_idcode::str, THD_usertaglist::tag, TAG_SETLABEL, THD_3dim_dataset::tagset, THD_init_datablock_keywords(), THD_init_datablock_labels(), THD_MAX_NAME, THD_store_datablock_stataux(), THD_usertag::ti, typ, THD_marker_set::type, THD_affine_warp::type, THD_linear_mapping::type, THD_talairach_12_warp::type, THD_statistics::type, THD_usertag::val, THD_marker_set::valid, THD_3dim_dataset::warp, THD_affine_warp::warp, THD_talairach_12_warp::warp, WARP_AFFINE_TYPE, THD_3dim_dataset::warp_parent_idcode, THD_3dim_dataset::warp_parent_name, WARP_TALAIRACH_12_TYPE, THD_usertag::x, XtFree, XtMalloc, THD_dataxes::xxmax, THD_dataxes::xxmin, THD_marker_set::xyz, THD_usertag::y, THD_dataxes::yymax, THD_dataxes::yymin, THD_usertag::z, THD_dataxes::zzmax, and THD_dataxes::zzmin.

Referenced by THD_3dim_from_block(), and THD_open_nifti().

00442 {
00443    THD_datablock     *blk ;
00444    THD_diskptr       *dkptr ;
00445    THD_dataxes       *daxes ;
00446    ATR_int           *atr_int = NULL ;
00447    ATR_float         *atr_flt = NULL;
00448    ATR_string        *atr_str = NULL ;
00449    int ii , view_type , func_type , dset_type , nx,ny,nz,nvox , nvals , ibr,typ ;
00450    Boolean ok ;
00451    char prefix[THD_MAX_NAME]="Unknown" ;
00452    MRI_IMAGE *qim ;
00453    int brick_ccode ;
00454 
00455 ENTRY("THD_datablock_apply_atr") ;
00456 
00457    if( !ISVALID_DSET(dset) ) EXRETURN ; /* bad input */
00458 
00459    blk   = dset->dblk   ;  if( blk == NULL   ) EXRETURN ;
00460    nvals = blk->nvals   ;  if( nvals <= 0    ) EXRETURN ;
00461    daxes = dset->daxes  ;  if( daxes == NULL ) EXRETURN ;
00462    dkptr = blk->diskptr ;
00463 
00464    /*-- brick labels --*/
00465 
00466    if( ATR_IS_STR(ATRNAME_BRICK_LABS) ){
00467      int ipos = -1 , ipold , ngood ;
00468 
00469      STATUS("brick labels") ;
00470      if( blk->brick_lab == NULL ) THD_init_datablock_labels( blk ) ;
00471 
00472      for( ibr=0 ; ibr < nvals ; ibr++ ){  /* loop over bricks */
00473 
00474        for( ipold = ipos++ ;                                   /* skip to */
00475             ipos < atr_str->nch && atr_str->ch[ipos] != '\0' ; /* next \0 */
00476             ipos++ ) /* nada */ ;                              /* or end. */
00477 
00478        ngood = ipos - ipold - 1 ;                 /* number of good chars */
00479        if( ngood > 0 ){
00480          XtFree(blk->brick_lab[ibr]) ;
00481          if( ngood > 32 ) ngood = 32 ;
00482          blk->brick_lab[ibr] = (char *) XtMalloc(sizeof(char)*(ngood+2)) ;
00483          memcpy( blk->brick_lab[ibr] , atr_str->ch+(ipold+1) , ngood ) ;
00484          blk->brick_lab[ibr][ngood] = '\0' ;
00485        }
00486 
00487         if( ipos >= atr_str->nch ) break ;  /* nothing more to do */
00488      } /* end of loop over sub-bricks */
00489    }
00490 
00491    /*-- keywords for the dataset itself --*/
00492 
00493    if( ATR_IS_STR(ATRNAME_KEYWORDS) ){
00494      STATUS("dataset keywords") ;
00495      dset->keywords = XtNewString( atr_str->ch ) ;
00496    }
00497 
00498    /*-- keywords for sub-bricks --*/
00499 
00500    if( ATR_IS_STR(ATRNAME_BRICK_KEYWORDS) ){
00501      int ipos = -1 , ipold , ngood ;
00502 
00503      STATUS("brick keywords") ;
00504      if( blk->brick_keywords == NULL ) THD_init_datablock_keywords( blk ) ;
00505 
00506      for( ibr=0 ; ibr < nvals ; ibr++ ){  /* loop over bricks */
00507 
00508        for( ipold = ipos++ ;                                   /* skip to */
00509             ipos < atr_str->nch && atr_str->ch[ipos] != '\0' ; /* next \0 */
00510             ipos++ ) /* nada */ ;                              /* or end. */
00511 
00512        ngood = ipos - ipold - 1 ;                 /* number of good chars */
00513        if( ngood > 0 ){
00514          XtFree(blk->brick_keywords[ibr]) ;
00515          blk->brick_keywords[ibr] = (char *) XtMalloc(sizeof(char)*(ngood+2)) ;
00516          memcpy( blk->brick_keywords[ibr] , atr_str->ch+(ipold+1) , ngood ) ;
00517          blk->brick_keywords[ibr][ngood] = '\0' ;
00518        }
00519 
00520        if( ipos >= atr_str->nch ) break ;  /* nothing more to do */
00521      } /* end of loop over sub-bricks */
00522    }
00523 
00524    /*-- auxiliary statistics stuff for each brick --*/
00525 
00526    if( ATR_IS_FLT(ATRNAME_BRICK_STATAUX) ){
00527      int ipos=0 , iv,nv,jv ;
00528 
00529      STATUS("brick stataux") ;
00530 
00531      /* attribute stores all stataux stuff as follows:
00532           sub-brick-index  statcode  no.-of-values value ... value
00533           sub-brick-index  statcode  no.-of-values value ... value, etc. */
00534 
00535      while( ipos <= atr_flt->nfl - 3 ){
00536        iv = (int) ( atr_flt->fl[ipos++] ) ;  /* which sub-brick */
00537        jv = (int) ( atr_flt->fl[ipos++] ) ;  /* statcode */
00538        nv = (int) ( atr_flt->fl[ipos++] ) ;  /* # of values that follow */
00539 
00540        if( nv > atr_flt->nfl - ipos ) nv = atr_flt->nfl - ipos ;
00541 
00542        THD_store_datablock_stataux( blk , iv , jv , nv , atr_flt->fl + ipos ) ;
00543        ipos += nv ;
00544      }
00545    }
00546 
00547    /*-- ID codes --*/
00548 
00549    if( ATR_IS_STR(ATRNAME_IDSTRING) )
00550      MCW_strncpy( dset->idcode.str , atr_str->ch , MCW_IDSIZE ) ;
00551 
00552    if( ATR_IS_STR(ATRNAME_IDDATE) )
00553      MCW_strncpy( dset->idcode.date , atr_str->ch , MCW_IDDATE ) ;
00554 
00555    if( ATR_IS_STR(ATRNAME_IDANATPAR) )
00556      MCW_strncpy( dset->anat_parent_idcode.str , atr_str->ch , MCW_IDSIZE ) ;
00557 
00558    if( ATR_IS_STR(ATRNAME_IDWARPPAR) )
00559      MCW_strncpy( dset->warp_parent_idcode.str , atr_str->ch , MCW_IDSIZE ) ;
00560 
00561    /*-- parent names --*/
00562 
00563    if( ATR_IS_STR(ATRNAME_ANATOMY_PARENT) &&
00564        ISZERO_IDCODE(dset->anat_parent_idcode) )
00565      MCW_strncpy( dset->anat_parent_name , atr_str->ch , THD_MAX_NAME ) ;
00566 
00567    if( ATR_IS_STR(ATRNAME_WARP_PARENT) &&
00568        ISZERO_IDCODE(dset->warp_parent_idcode) )
00569      MCW_strncpy( dset->warp_parent_name , atr_str->ch , THD_MAX_NAME ) ;
00570 
00571    if( ATR_IS_STR(ATRNAME_DATANAME) )
00572      MCW_strncpy( dset->self_name , atr_str->ch , THD_MAX_NAME ) ;
00573 
00574    /*-- markers --*/
00575 
00576    if( ATR_IS_FLT(ATRNAME_MARKSXYZ) && ATR_IS_STR(ATRNAME_MARKSLAB) ){
00577      int im , llen ;
00578      THD_ivec3 iv ;
00579      float xxdown,xxup , yydown,yyup , zzdown,zzup ;
00580 
00581      STATUS("markers") ;
00582 
00583      if( dset->markers == NULL ){
00584        dset->markers = myXtNew( THD_marker_set ) ;  /* new set */
00585        ADDTO_KILL(dset->kl , dset->markers) ;
00586      }
00587 
00588      COPY_INTO_STRUCT( *(dset->markers) ,  /* actual struct */
00589                        MARKS_FSTART ,      /* byte offset */
00590                        float ,             /* type being copied */
00591                        atr_flt->fl ,       /* start of source */
00592                        MARKS_FSIZE  ) ;    /* number of floats */
00593 
00594      COPY_INTO_STRUCT( *(dset->markers) ,
00595                        MARKS_LSTART ,
00596                        char ,
00597                        atr_str->ch ,
00598                        MARKS_LSIZE  ) ;
00599 
00600      xxdown = daxes->xxmin ; xxup = daxes->xxmax ;
00601      yydown = daxes->yymin ; yyup = daxes->yymax ;
00602      zzdown = daxes->zzmin ; zzup = daxes->zzmax ;
00603 
00604      dset->markers->numdef = dset->markers->numset = 0 ;
00605 
00606      for( im=0 ; im < MARKS_MAXNUM ; im++ ){
00607        llen = strlen( &(dset->markers->label[im][0]) ) ;
00608        dset->markers->valid[im]   =
00609           (llen > 0) &&
00610           ( dset->markers->xyz[im][0] >= xxdown ) &&
00611           ( dset->markers->xyz[im][0] <= xxup   ) &&
00612           ( dset->markers->xyz[im][1] >= yydown ) &&
00613           ( dset->markers->xyz[im][1] <= yyup   ) &&
00614           ( dset->markers->xyz[im][2] >= zzdown ) &&
00615           ( dset->markers->xyz[im][2] <= zzup   )    ;
00616 
00617        if( dset->markers->valid[im] ) (dset->markers->numset)++ ;
00618 
00619        if( llen > 0 ) (dset->markers->numdef)++ ;
00620 
00621        dset->markers->ovcolor[im] = -1 ;  /* default color */
00622      }
00623 
00624      if( ATR_IS_STR(ATRNAME_MARKSHELP) ){
00625        COPY_INTO_STRUCT( *(dset->markers) ,
00626                           MARKS_HSTART ,
00627                           char ,
00628                           atr_str->ch ,
00629                           MARKS_HSIZE  ) ;
00630      } else {
00631        for( im=0 ; im < MARKS_MAXNUM ; im++ )   /* no help */
00632          dset->markers->help[im][0] = '\0' ;
00633      }
00634 
00635      if( ATR_IS_INT(ATRNAME_MARKSFLAG) ){
00636        COPY_INTO_STRUCT( *(dset->markers) ,
00637                          MARKS_ASTART ,
00638                          int ,
00639                          atr_int->in ,
00640                          MARKS_ASIZE  ) ;
00641        dset->markers->type = dset->markers->aflags[0] ;
00642      } else {
00643        for( im=0 ; im < MARKS_MAXFLAG ; im++ )
00644          dset->markers->aflags[im] = -1 ;
00645      }
00646    }
00647 
00648    /*-- warp --*/
00649 
00650    if( ATR_IS_INT(ATRNAME_WARP_TYPE) && ATR_IS_FLT(ATRNAME_WARP_DATA) ){
00651      int wtype = atr_int->in[0] , rtype = atr_int->in[1]  ;
00652 
00653      STATUS("warp") ;
00654 
00655      dset->warp = myXtNew( THD_warp ) ;
00656      ADDTO_KILL( dset->kl , dset->warp ) ;
00657      switch( wtype ){
00658        case WARP_AFFINE_TYPE:{
00659          THD_affine_warp *ww = (THD_affine_warp *) dset->warp ;
00660          ww->type       = wtype ;
00661          ww->resam_type = rtype ;
00662          ww->warp.type  = MAPPING_LINEAR_TYPE ;
00663 
00664          COPY_INTO_STRUCT( ww->warp ,
00665                            MAPPING_LINEAR_FSTART ,
00666                            float ,
00667                            atr_flt->fl ,
00668                            MAPPING_LINEAR_FSIZE ) ;
00669        }
00670        break ;  /* end affine warp */
00671 
00672        case WARP_TALAIRACH_12_TYPE:{
00673          THD_talairach_12_warp *ww =
00674             (THD_talairach_12_warp *) dset->warp ;
00675          int iw , ioff ;
00676          ww->type       = wtype ;
00677          ww->resam_type = rtype ;
00678          for( iw=0 ; iw < 12 ; iw++ ){
00679             ww->warp[iw].type = MAPPING_LINEAR_TYPE ;
00680 
00681             ioff = iw * MAPPING_LINEAR_FSIZE ;
00682 
00683             COPY_INTO_STRUCT( ww->warp[iw] ,
00684                               MAPPING_LINEAR_FSTART ,
00685                               float ,
00686                               &(atr_flt->fl[ioff]) ,
00687                               MAPPING_LINEAR_FSIZE ) ;
00688 
00689          }  /* end loop over 12 warps */
00690        }
00691        break ;  /* end talairach_12 warp */
00692 
00693      } /* end of switch on warp type */
00694    }
00695 
00696    /*-- brick stats --*/
00697 
00698    if( ATR_IS_FLT(ATRNAME_BRICK_STATS) ){
00699      int qq ;
00700      STATUS("brick statistics") ;
00701      dset->stats         = myXtNew( THD_statistics ) ;
00702      dset->stats->type   = STATISTICS_TYPE ;
00703      dset->stats->parent = (XtPointer) dset ;
00704      dset->stats->nbstat = blk->nvals ;
00705      dset->stats->bstat  = (THD_brick_stats *)
00706                               XtMalloc( sizeof(THD_brick_stats) * blk->nvals ) ;
00707      for( qq=0 ; qq < blk->nvals ; qq++ ){
00708        if( 2*qq+1 < atr_flt->nfl ){
00709            dset->stats->bstat[qq].min = atr_flt->fl[2*qq] ;
00710            dset->stats->bstat[qq].max = atr_flt->fl[2*qq+1] ;
00711        } else {
00712            INVALIDATE_BSTAT( dset->stats->bstat[qq] ) ;
00713        }
00714      }
00715      ADDTO_KILL( dset->kl , dset->stats->bstat ) ;
00716      ADDTO_KILL( dset->kl , dset->stats ) ;
00717    }
00718 
00719    /*-- tagset --*/
00720 
00721    if( ATR_IS_INT(ATRNAME_TAGSET_NUM)    &&
00722        ATR_IS_FLT(ATRNAME_TAGSET_FLOATS) &&
00723        ATR_IS_STR(ATRNAME_TAGSET_LABELS)    ){
00724 
00725      int nin=atr_int->nin , nfl=atr_flt->nfl , nch=atr_str->nch ;
00726      int ii , ntag , nfper , jj , kk ;
00727 
00728      STATUS("tagset") ;
00729      ntag  = atr_int->in[0] ;  /* number of tags */
00730      nfper = atr_int->in[1] ;  /* number of floats per tag */
00731 
00732      if( ntag > MAX_TAG_NUM ) ntag = MAX_TAG_NUM ;
00733 
00734      dset->tagset = myXtNew( THD_usertaglist ) ;  /* create tagset */
00735      ADDTO_KILL( dset->kl , dset->tagset ) ;
00736 
00737      dset->tagset->num = ntag ;
00738      strcpy( dset->tagset->label , "Bebe Rebozo" ) ;  /* not used */
00739 
00740      /* read out tag values; allow for chance there isn't enough data */
00741 
00742 #undef  TF
00743 #define TF(i,j) \
00744   ( ((j)<nfper && (i)*nfper+(j)<nfl) ? atr_flt->fl[(i)*nfper+(j)] : -666.0 )
00745 
00746      for( ii=0 ; ii < ntag ; ii++ ){
00747        dset->tagset->tag[ii].x   = TF(ii,0) ; /* coords */
00748        dset->tagset->tag[ii].y   = TF(ii,1) ;
00749        dset->tagset->tag[ii].z   = TF(ii,2) ;
00750        dset->tagset->tag[ii].val = TF(ii,3) ; /* value */
00751        dset->tagset->tag[ii].ti  = TF(ii,4) ; /* time index: if < 0, not set */
00752        if( dset->tagset->tag[ii].ti >= 0 ){
00753          dset->tagset->tag[ii].set = 1 ;
00754        } else {
00755          dset->tagset->tag[ii].set = 0 ; dset->tagset->tag[ii].ti = 0 ;
00756        }
00757      }
00758 #undef TF
00759 
00760      /* read out tag labels; allow for empty labels */
00761 
00762      jj = 0 ;
00763      for( ii=0 ; ii < ntag ; ii++ ){
00764        if( jj < nch ){
00765          kk = strlen( atr_str->ch + jj ) ;
00766          if( kk > 0 ) TAG_SETLABEL( dset->tagset->tag[ii] , atr_str->ch + jj );
00767          else         sprintf( dset->tagset->tag[ii].label , "Tag %d" , ii+1 );
00768          jj += kk+1 ;
00769        } else {
00770          sprintf( dset->tagset->tag[ii].label , "Tag %d" , ii+1 ) ;
00771        }
00772      }
00773    }
00774 
00775    EXRETURN ;
00776 }

int THD_datablock_from_atr THD_datablock   dblk,
char *    dirname,
char *    headname
 

Take the internal attributes and load the datablock struct up. -----------------------------------------------------------------------------

Definition at line 138 of file thd_initdblk.c.

References AFNI_FIRST_STATCODE, AFNI_LAST_STATCODE, ATRNAME_BRICK_FLTFAC, ATRNAME_BRICK_KEYWORDS, ATRNAME_BRICK_LABS, ATRNAME_BRICK_STATAUX, ATRNAME_BRICK_TYPES, ATRNAME_BYTEORDER, ATRNAME_DATASET_DIMENSIONS, ATRNAME_DATASET_RANK, ATRNAME_SCENE_TYPE, THD_datablock::brick_fac, THD_datablock::brick_keywords, THD_datablock::brick_lab, THD_diskptr::brick_name, THD_diskptr::byte_order, BYTE_ORDER_STRING, ATR_string::ch, COMPRESS_filecode(), COMPRESS_NOFILE, DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DBLK_BRICK_TYPE, DBLK_mmapfix, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, FILENAME_TO_PREFIX, ATR_float::fl, ATR_int::in, LSB_FIRST_STRING, THD_datablock::malloc_type, MCW_strncpy, MMAP_THRESHOLD, MSB_FIRST_STRING, MYHEAD, native_order, THD_datablock::natr, ATR_string::nch, ATR_float::nfl, NI_decode_string_list(), NI_delete_str_array, NI_stat_decode(), NI_stat_numparam(), ATR_int::nin, no_mmap, no_ordwarn, NI_str_array::num, THD_diskptr::nvals, THD_datablock::nvals, nz, ORDER_LEN, THD_diskptr::rank, RETURN, STATUS, STORAGE_BY_BRICK, STORAGE_BY_VOLUMES, THD_diskptr::storage_mode, STORAGE_UNDEFINED, NI_str_array::str, THD_datum_constant(), THD_find_float_atr(), THD_find_int_atr(), THD_find_string_atr(), THD_init_datablock_brick(), THD_init_datablock_keywords(), THD_init_datablock_labels(), THD_init_diskptr_names(), THD_MAX_NAME, THD_MAX_RANK, THD_MIN_RANK, THD_store_datablock_stataux(), THD_datablock::total_bytes, typ, XtFree, and XtMalloc.

Referenced by THD_init_one_datablock(), and THD_niml_to_dataset().

00139 {
00140    THD_diskptr       *dkptr ;
00141    ATR_int           *atr_rank , *atr_dimen , *atr_scene , *atr_btype ;
00142    ATR_float         *atr_flt ;
00143    ATR_string        *atr_labs ;
00144    int ii , view_type , func_type , dset_type , nx,ny,nz,nvox , nvals , ibr,typ ;
00145    Boolean ok ;
00146    char prefix[THD_MAX_NAME]="Unknown" ;
00147    MRI_IMAGE *qim ;
00148    int brick_ccode ;
00149 
00150 ENTRY("THD_datablock_from_atr") ;
00151 
00152    if( dblk == NULL || dblk->natr <= 0 ) RETURN(0) ; /* bad input */
00153 
00154    dkptr = dblk->diskptr ;
00155 
00156    /*-- get relevant attributes: rank, dimensions, view_type & func_type --*/
00157 
00158    atr_rank  = THD_find_int_atr( dblk , ATRNAME_DATASET_RANK ) ;
00159    atr_dimen = THD_find_int_atr( dblk , ATRNAME_DATASET_DIMENSIONS ) ;
00160    atr_scene = THD_find_int_atr( dblk , ATRNAME_SCENE_TYPE ) ;
00161 
00162    /*-- missing an attribute ==> quit now --*/
00163 
00164    if( atr_rank == NULL || atr_dimen == NULL || atr_scene == NULL ) RETURN(0) ;
00165 
00166    /*-- load type codes from SCENE attribute --*/
00167 
00168    STATUS("loading *_type from SCENE") ;
00169 
00170    view_type = atr_scene->in[0] ;
00171    func_type = atr_scene->in[1] ;
00172    dset_type = atr_scene->in[2] ;
00173 
00174    /*-- load other values from attributes into relevant places --*/
00175 
00176    ok   = True ;
00177    nvox = 1 ;
00178 
00179    STATUS("loading from RANK") ;
00180 
00181    dkptr->rank = atr_rank->in[0] ;                /* N.B.: rank isn't used much */
00182    dkptr->nvals = dblk->nvals = nvals = atr_rank->in[1] ;  /* but nvals is used */
00183 
00184    STATUS("loading from DIMENSIONS") ;
00185 
00186    for( ii=0 ; ii < dkptr->rank ; ii++ ){
00187      dkptr->dimsizes[ii] = atr_dimen->in[ii] ;
00188      ok                  = ( ok && dkptr->dimsizes[ii] >= 1 ) ;
00189      nvox               *= dkptr->dimsizes[ii] ;
00190    }
00191 
00192 #if 0
00193    if( PRINT_TRACING ){
00194      char str[256] ;
00195      sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d nvox=%d",
00196              dkptr->rank , dkptr->nvals ,
00197              dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] , nvox ) ;
00198      STATUS(str) ;
00199    }
00200 #endif
00201 
00202    if( !ok || nvals < 1 ||
00203        dkptr->rank < THD_MIN_RANK || dkptr->rank > THD_MAX_RANK ){
00204      STATUS("bad rank!!??") ;
00205      RETURN(0) ;
00206    }
00207 
00208    /*-- create the storage filenames --*/
00209 
00210    STATUS("creating storage filenames") ;
00211 
00212    if( headname != NULL && strchr(headname,'+') != NULL ){
00213      FILENAME_TO_PREFIX(headname,prefix) ;
00214      THD_init_diskptr_names( dkptr, dirname,NULL,prefix , view_type , True ) ;
00215    } else {
00216      if( headname != NULL ) MCW_strncpy(prefix,headname,THD_MAX_NAME) ;
00217      THD_init_diskptr_names( dkptr, dirname,NULL,prefix , view_type , True ) ;
00218    }
00219 
00220    /*-- determine if the BRIK file exists --*/
00221 
00222    STATUS("checking if .BRIK file exists") ;
00223 
00224    brick_ccode = COMPRESS_filecode(dkptr->brick_name) ;
00225    if( brick_ccode != COMPRESS_NOFILE )
00226      dkptr->storage_mode = STORAGE_BY_BRICK ;  /* a .BRIK file */
00227 
00228    /*-- if VOLUME_FILENAMES attribute exists, make it so [20 Jun 2002] --*/
00229 
00230    if( headname != NULL && dkptr->storage_mode == STORAGE_UNDEFINED ){
00231      atr_labs = THD_find_string_atr(dblk,"VOLUME_FILENAMES") ;
00232      if( atr_labs != NULL ){
00233        dkptr->storage_mode = STORAGE_BY_VOLUMES ;
00234        dblk->malloc_type   = DATABLOCK_MEM_MALLOC ;
00235      }
00236    }
00237 
00238    /*-- now set the memory allocation codes, etc. --*/
00239 
00240    dblk->brick_fac = (float *) XtMalloc( sizeof(float) * nvals ) ;
00241    for( ibr=0 ; ibr < nvals ; ibr++ ) dblk->brick_fac[ibr] = 0.0 ;
00242 
00243    /* scaling factors from short type to float type, if nonzero */
00244 
00245    atr_flt = THD_find_float_atr( dblk , ATRNAME_BRICK_FLTFAC ) ;
00246    if( atr_flt != NULL ){
00247      for( ibr=0 ; ibr < nvals && ibr < atr_flt->nfl ; ibr++ )
00248        dblk->brick_fac[ibr] = atr_flt->fl[ibr] ;
00249    }
00250 
00251    /** Now create an empty shell of the "brick" == the data structure
00252        that will hold all the voxel data.  Note that all datablocks
00253        will have a brick, even if they never actually contain data
00254        themselves (are only warp-on-demand).
00255 
00256        If the BRICK_TYPES input attribute doesn't exist, then all
00257        sub-bricks are shorts.  This makes the code work with old-style
00258        datasets, which were always made up of shorts.
00259    **/
00260 
00261    atr_btype = THD_find_int_atr( dblk , ATRNAME_BRICK_TYPES ) ;
00262 
00263    if( atr_btype == NULL ){
00264      THD_init_datablock_brick( dblk , MRI_short , NULL ) ;
00265    } else {
00266      THD_init_datablock_brick( dblk , atr_btype->nin , atr_btype->in ) ;
00267    }
00268 
00269    if( !THD_datum_constant(dblk) ){ /* 15 Sep 2004 */
00270      fprintf(stderr,
00271              "\n** WARNING: File %s has mixed-type sub-bricks. ", MYHEAD ) ;
00272    }
00273 
00274    /* 25 April 1998: check if the byte order is stored inside */
00275 
00276    atr_labs = THD_find_string_atr( dblk , ATRNAME_BYTEORDER ) ;
00277    if( atr_labs != NULL && atr_labs->nch > 0 ){
00278 
00279      if( strncmp(atr_labs->ch,LSB_FIRST_STRING,ORDER_LEN) == 0 )
00280        dkptr->byte_order = LSB_FIRST ;
00281      else if( strncmp(atr_labs->ch,MSB_FIRST_STRING,ORDER_LEN) == 0 )
00282        dkptr->byte_order = MSB_FIRST ;
00283      else
00284        fprintf(stderr,"*** Unknown %s found in dataset %s\n",
00285                ATRNAME_BYTEORDER , MYHEAD ) ;
00286 
00287    } else if( !no_ordwarn                         &&
00288               DBLK_BRICK_TYPE(dblk,0) != MRI_byte &&
00289               dblk->diskptr->storage_mode == STORAGE_BY_BRICK ){ /* 20 Sep 1999 */
00290 
00291      static int first=1 ;
00292      if( first ){
00293        fprintf(stderr,
00294          "\n*** The situation below can be rectified with program '3drefit -byteorder':\n");
00295        first = 0 ;
00296      }
00297      fprintf(stderr," ** Dataset %s: assuming byteorder %s\n",
00298              MYHEAD , BYTE_ORDER_STRING(dkptr->byte_order)  ) ;
00299    }
00300 
00301    /* if the data is not on disk, the flag remains at DATABLOCK_MEM_UNDEFINED,
00302       otherwise the flag says how the memory for the bricks is to be created. */
00303 
00304    if( dkptr->storage_mode == STORAGE_BY_BRICK ){
00305 #if MMAP_THRESHOLD > 0
00306      dblk->malloc_type = (dblk->total_bytes > MMAP_THRESHOLD)
00307                          ? DATABLOCK_MEM_MMAP : DATABLOCK_MEM_MALLOC ;
00308      DBLK_mmapfix(dblk) ;  /* 18 Mar 2005 */
00309 #else
00310      dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00311 #endif
00312 
00313      /* must be malloc-ed if:
00314            data is compressed,
00315            data is not in native byte order, or
00316            user explicity forbids use of mmap   */
00317 
00318      if( brick_ccode >= 0 || dkptr->byte_order != native_order || no_mmap )
00319         dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00320    }
00321 
00322    /* 30 Nov 1997: create the labels for sub-bricks */
00323 
00324    THD_init_datablock_labels( dblk ) ;
00325 
00326    atr_labs = THD_find_string_atr( dblk , ATRNAME_BRICK_LABS ) ;
00327 
00328    if( atr_labs != NULL && atr_labs->nch > 0 ){  /* create labels from attribute */
00329      int ipos = -1 , ipold , ngood ;
00330 
00331      for( ibr=0 ; ibr < nvals ; ibr++ ){  /* loop over bricks */
00332 
00333        for( ipold = ipos++ ;                                     /* skip to */
00334             ipos < atr_labs->nch && atr_labs->ch[ipos] != '\0' ; /* next \0 */
00335             ipos++ ) /* nada */ ;                                /* or end. */
00336 
00337        ngood = ipos - ipold - 1 ;                   /* number of good chars */
00338        if( ngood > 0 ){
00339          XtFree(dblk->brick_lab[ibr]) ;
00340          if( ngood > 32 ) ngood = 32 ;      /* 02 Sep 2004 */
00341          dblk->brick_lab[ibr] = (char *) XtMalloc(sizeof(char)*(ngood+2)) ;
00342          memcpy( dblk->brick_lab[ibr] , atr_labs->ch+(ipold+1) , ngood ) ;
00343          dblk->brick_lab[ibr][ngood] = '\0' ;
00344        }
00345 
00346         if( ipos >= atr_labs->nch ) break ;  /* nothing more to do */
00347      } /* end of loop over sub-bricks */
00348    }
00349 
00350    /* create the keywords for sub-bricks */
00351 
00352    THD_init_datablock_keywords( dblk ) ;
00353 
00354    atr_labs = THD_find_string_atr( dblk , ATRNAME_BRICK_KEYWORDS ) ;
00355 
00356    if( atr_labs != NULL && atr_labs->nch > 0 ){  /* create keywords from attribute */
00357      int ipos = -1 , ipold , ngood ;
00358 
00359      for( ibr=0 ; ibr < nvals ; ibr++ ){  /* loop over bricks */
00360 
00361        for( ipold = ipos++ ;                                     /* skip to */
00362             ipos < atr_labs->nch && atr_labs->ch[ipos] != '\0' ; /* next \0 */
00363             ipos++ ) /* nada */ ;                                /* or end. */
00364 
00365        ngood = ipos - ipold - 1 ;                   /* number of good chars */
00366        if( ngood > 0 ){
00367          XtFree(dblk->brick_keywords[ibr]) ;
00368          dblk->brick_keywords[ibr] = (char *) XtMalloc(sizeof(char)*(ngood+2)) ;
00369          memcpy( dblk->brick_keywords[ibr] , atr_labs->ch+(ipold+1) , ngood ) ;
00370          dblk->brick_keywords[ibr][ngood] = '\0' ;
00371        }
00372 
00373        if( ipos >= atr_labs->nch ) break ;  /* nothing more to do */
00374      } /* end of loop over sub-bricks */
00375    }
00376 
00377    /* create the auxiliary statistics stuff for each brick, if present */
00378 
00379    atr_labs = THD_find_string_atr( dblk , "BRICK_STATSYM" ) ;  /* 01 Jun 2005 */
00380    if( atr_labs != NULL && atr_labs->nch > 0 ){
00381      NI_str_array *sar ; int scode,np ; float parm[3] ;
00382      sar = NI_decode_string_list( atr_labs->ch , ";" ) ;
00383      if( sar != NULL && sar->num > 0 ){
00384        for( ibr=0 ; ibr < nvals && ibr < sar->num ; ibr++ ){
00385          NI_stat_decode( sar->str[ibr] , &scode , parm,parm+1,parm+2 ) ;
00386          if( scode >= AFNI_FIRST_STATCODE && scode <= AFNI_LAST_STATCODE ){
00387            np = NI_stat_numparam(scode) ;
00388            THD_store_datablock_stataux( dblk , ibr,scode,np,parm ) ;
00389          }
00390        }
00391        NI_delete_str_array(sar) ;
00392      }
00393    } else {          /*--- the olde way to get ye brick stataux parameters ---*/
00394      atr_flt = THD_find_float_atr( dblk , ATRNAME_BRICK_STATAUX ) ;
00395      if( atr_flt != NULL && atr_flt->nfl >= 3 ){
00396        int ipos=0 , iv,nv,jv ;
00397 
00398        /* attribute stores all stataux stuff as follows:
00399             sub-brick-index  statcode  no.-of-values value ... value
00400             sub-brick-index  statcode  no.-of-values value ... value, etc. */
00401 
00402        while( ipos <= atr_flt->nfl - 3 ){
00403          iv = (int) ( atr_flt->fl[ipos++] ) ;  /* which sub-brick */
00404          jv = (int) ( atr_flt->fl[ipos++] ) ;  /* statcode */
00405          nv = (int) ( atr_flt->fl[ipos++] ) ;  /* # of values that follow */
00406 
00407          if( nv > atr_flt->nfl - ipos ) nv = atr_flt->nfl - ipos ;
00408 
00409          THD_store_datablock_stataux( dblk , iv , jv , nv , atr_flt->fl + ipos ) ;
00410          ipos += nv ;
00411        }
00412      }
00413    }
00414 #if 0
00415    if( PRINT_TRACING ){
00416      char str[256] ;
00417      sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d",
00418              dkptr->rank , dkptr->nvals ,
00419              dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] ) ;
00420      STATUS(str) ;
00421    }
00422 #endif
00423 
00424    RETURN(1) ;
00425 }

char* THD_dataset_headname char *   ,
char *   ,
int   
 

Definition at line 199 of file thd_opendset.c.

References ADN_directory_name, ADN_none, ADN_prefix, ADN_view_type, THD_3dim_dataset::dblk, THD_datablock::diskptr, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, FIRST_VIEW_TYPE, THD_diskptr::header_name, LAST_VIEW_TYPE, malloc, RETURN, and THD_delete_3dim_dataset().

Referenced by THD_open_3dcalc().

00200 {
00201    THD_3dim_dataset *dset ;
00202    char *str ; int ll ;
00203 
00204 ENTRY("THD_dataset_headname") ;
00205 
00206    if( pname == NULL ) RETURN(NULL) ;
00207 
00208    dset = EDIT_empty_copy(NULL) ;
00209    EDIT_dset_items( dset , ADN_prefix , pname , ADN_none ) ;
00210 
00211    if( sname != NULL )
00212       EDIT_dset_items( dset , ADN_directory_name , sname , ADN_none ) ;
00213 
00214    if( vt >= FIRST_VIEW_TYPE && vt <= LAST_VIEW_TYPE )
00215       EDIT_dset_items( dset , ADN_view_type , vt , ADN_none ) ;
00216 
00217    ll = strlen(dset->dblk->diskptr->header_name) + 1 ;
00218    str = (char *) malloc(sizeof(char)*ll ) ;
00219    strcpy( str , dset->dblk->diskptr->header_name ) ;
00220 
00221    THD_delete_3dim_dataset( dset , False ) ;
00222    RETURN(str) ;
00223 }

char* THD_dataset_info THD_3dim_dataset  ,
int   
 

Definition at line 25 of file thd_info.c.

References AFMALL, THD_3dim_dataset::anat_parent_idcode, THD_3dim_dataset::anat_parent_name, ATRNAME_BYTEORDER, THD_statistics::bstat, MCW_idcode::date, THD_3dim_dataset::daxes, DAXES_NUM, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_BRICK_FACTOR, DSET_BRICK_KEYWORDS, DSET_BRICK_LAB, DSET_BRICK_STATCODE, DSET_BRICK_STATPAR, DSET_BRICK_TYPE, DSET_BRIKNAME, DSET_BYTEORDER, DSET_FILECODE, DSET_IS_BRIK, DSET_KEYWORDS, DSET_NUM_TIMES, DSET_NVALS_PER_TIME, THD_timeaxis::dz_sl, ENTRY, free, FUNC_IS_STAT, THD_3dim_dataset::func_type, i, THD_3dim_dataset::idcode, ATR_int::in, ISANAT, ISFUNC, ISVALID_3DIM_DATASET, ISVALID_STATISTIC, ISZERO_IDCODE, LOAD_FVEC3, LSB_FIRST_STRING, THD_brick_stats::max, THD_brick_stats::min, mmm, mri_short_order(), MSB_FIRST_STRING, n1, n2, THD_timeaxis::nsl, THD_usertaglist::num, THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_R2L_TYPE, RETURN, THD_usertag::set, THD_3dim_dataset::stat_aux, THD_3dim_dataset::stats, STORAGE_BY_1D, STORAGE_BY_3D, STORAGE_BY_ANALYZE, STORAGE_BY_BRICK, STORAGE_BY_CTFMRI, STORAGE_BY_CTFSAM, STORAGE_BY_MINC, STORAGE_BY_MPEG, STORAGE_BY_NIFTI, STORAGE_BY_VOLUMES, THD_diskptr::storage_mode, MCW_idcode::str, SZMAX, THD_usertaglist::tag, THD_3dim_dataset::tagset, THD_3dim_dataset::taxis, THD_3dmm_to_dicomm(), THD_find_int_atr(), THD_find_string_atr(), THD_zzprintf(), THD_timeaxis::toff_sl, tross_Get_History(), tross_Get_Note(), tross_Get_Notedate(), THD_timeaxis::ttdel, THD_timeaxis::ttorg, THD_timeaxis::units_type, UNITS_TYPE_LABEL, THD_3dim_dataset::warp_parent_idcode, THD_3dim_dataset::warp_parent_name, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::yyorient, ZMAX, THD_dataxes::zzdel, THD_dataxes::zzorg, and THD_dataxes::zzorient.

Referenced by AFNI_misc_CB(), and main().

00026 {
00027    THD_dataxes      *daxes ;
00028    THD_fvec3 fv1 , fv2 , fv3 ;
00029    THD_ivec3 iv ;
00030    int ival , ntimes , nval_per , n1,n2,n3 , kv,npar ;
00031    float tf ;
00032 
00033    static char *RR="[R]" , *LL="[L]" ,
00034                *PP="[P]" , *AA="[A]" ,
00035                *SS="[S]" , *II="[I]" , *ZZ="   " ;
00036    char *xlbot , *xltop , *ylbot , *yltop , *zlbot , *zltop , *cpt ;
00037    char str[256] ;
00038    int nstr ;
00039 
00040    char *outbuf = NULL ;
00041 
00042 ENTRY("THD_dataset_info") ;
00043 
00044    if( ! ISVALID_3DIM_DATASET(dset) ) RETURN(NULL) ;
00045 
00046    daxes = dset->daxes ;
00047 
00048    if( DSET_IS_BRIK(dset) )
00049      outbuf = THD_zzprintf(outbuf,"Dataset File:    %s\n" , DSET_FILECODE(dset) ) ;
00050    else
00051      outbuf = THD_zzprintf(outbuf,"Dataset File:    %s\n" , DSET_BRIKNAME(dset) ) ;
00052 
00053    outbuf = THD_zzprintf(outbuf,"Identifier Code: %s  Creation Date: %s\n" ,
00054              dset->idcode.str , dset->idcode.date ) ;
00055 
00056    if( ISANAT(dset) ){
00057       outbuf = THD_zzprintf(outbuf,"Dataset Type:    %s (-%s)\n",
00058                 ANAT_typestr[dset->func_type] , ANAT_prefixstr[dset->func_type] ) ;
00059    } else {
00060       outbuf = THD_zzprintf(outbuf,"Dataset Type:    %s (-%s)\n",
00061                 FUNC_typestr[dset->func_type] , FUNC_prefixstr[dset->func_type] ) ;
00062    }
00063 
00064    /* 25 April 1998: do byte order stuff */
00065 
00066    switch( DSET_BYTEORDER(dset) ){
00067       case LSB_FIRST:
00068          outbuf = THD_zzprintf(outbuf,"Byte Order:      %s" , LSB_FIRST_STRING) ;
00069       break ;
00070       case MSB_FIRST:
00071          outbuf = THD_zzprintf(outbuf,"Byte Order:      %s" , MSB_FIRST_STRING) ;
00072       break ;
00073    }
00074 
00075    if( THD_find_string_atr(dset->dblk,ATRNAME_BYTEORDER) == NULL ) /* 19 Sep 1999 */
00076       outbuf = THD_zzprintf(outbuf," {assumed}") ;
00077 
00078    kv = mri_short_order() ;
00079    switch( kv ){
00080       case LSB_FIRST:
00081          outbuf = THD_zzprintf(outbuf," [this CPU native = %s]\n" , LSB_FIRST_STRING) ;
00082       break ;
00083       case MSB_FIRST:
00084          outbuf = THD_zzprintf(outbuf," [this CPU native = %s]\n" , MSB_FIRST_STRING) ;
00085       break ;
00086    }
00087 
00088    /*-- 21 Jun 2002: print storage mode --*/
00089 
00090    switch( dset->dblk->diskptr->storage_mode ){
00091      default: 
00092        outbuf = THD_zzprintf(outbuf,"Storage Mode:    Undefined\n") ; break ;
00093 
00094      case STORAGE_BY_BRICK:
00095        outbuf = THD_zzprintf(outbuf,"Storage Mode:    BRIK file\n") ; break ;
00096 
00097      case STORAGE_BY_MINC:
00098        outbuf = THD_zzprintf(outbuf,"Storage Mode:    MINC file\n") ; break ;
00099 
00100      case STORAGE_BY_VOLUMES:
00101        outbuf = THD_zzprintf(outbuf,"Storage Mode:    Volume file(s)\n") ; break ;
00102 
00103      case STORAGE_BY_ANALYZE:
00104        outbuf = THD_zzprintf(outbuf,"Storage Mode:    ANALYZE files\n") ; break ;
00105 
00106      case STORAGE_BY_CTFMRI:
00107        outbuf = THD_zzprintf(outbuf,"Storage Mode:    CTF MRI file\n") ; break ;
00108 
00109      case STORAGE_BY_CTFSAM:
00110        outbuf = THD_zzprintf(outbuf,"Storage Mode:    CTF SAM file\n") ; break ;
00111 
00112      case STORAGE_BY_1D:
00113        outbuf = THD_zzprintf(outbuf,"Storage Mode:    AFNI .1D file\n") ; break ;
00114 
00115      case STORAGE_BY_3D:
00116        outbuf = THD_zzprintf(outbuf,"Storage Mode:    AFNI .3D file\n") ; break ;
00117 
00118      case STORAGE_BY_NIFTI:
00119        outbuf = THD_zzprintf(outbuf,"Storage Mode:    NIFTI file\n") ; break ;
00120 
00121      case STORAGE_BY_MPEG:
00122        outbuf = THD_zzprintf(outbuf,"Storage Mode:    MPEG file\n") ; break ;
00123    }
00124 
00125    /*-- keywords --*/
00126 
00127    if( verbose >= 0 ){
00128     cpt = DSET_KEYWORDS(dset) ;
00129     if( cpt != NULL && cpt[0] != '\0' )
00130        outbuf = THD_zzprintf(outbuf,"Keywords:        %s\n" , cpt ) ;
00131    }
00132 
00133    /*-- idcodes --*/
00134 
00135   if( verbose >= 0 ){
00136    if( ! ISZERO_IDCODE(dset->anat_parent_idcode) )
00137       outbuf = THD_zzprintf(outbuf,"Anatomy Parent:  %s [%s]\n" ,
00138                 dset->anat_parent_name , dset->anat_parent_idcode.str ) ;
00139    else if( strlen(dset->anat_parent_name) > 0 )
00140       outbuf = THD_zzprintf(outbuf,"Anatomy Parent:  %s\n" , dset->anat_parent_name ) ;
00141 
00142    if( ! ISZERO_IDCODE(dset->warp_parent_idcode) )
00143       outbuf = THD_zzprintf(outbuf,"Warp Parent:     %s [%s]\n" ,
00144                  dset->warp_parent_name , dset->warp_parent_idcode.str) ;
00145    else if( strlen(dset->warp_parent_name) > 0 )
00146       outbuf = THD_zzprintf(outbuf,"Warp Parent:     %s\n" , dset->warp_parent_name ) ;
00147   }
00148 
00149    /*-- tagset --*/
00150 
00151    if( verbose > 0 && dset->tagset != NULL && dset->tagset->num > 0 ){
00152       int ii , ns=0 ;
00153       for( ii=0 ; ii < dset->tagset->num ; ii++ )
00154          if( dset->tagset->tag[ii].set ) ns++ ;
00155 
00156       outbuf = THD_zzprintf(outbuf,"Tagset:          %d set [out of %d total]\n",
00157                             ns , dset->tagset->num ) ;
00158    }
00159 
00160    outbuf = THD_zzprintf(outbuf,
00161       "Data Axes Orientation:\n"
00162       "  first  (x) = %s\n"
00163       "  second (y) = %s\n"
00164       "  third  (z) = %s   [-orient %c%c%c]\n" ,
00165     ORIENT_typestr[daxes->xxorient] ,
00166       ORIENT_typestr[daxes->yyorient] ,
00167       ORIENT_typestr[daxes->zzorient] ,
00168     ORIENT_typestr[daxes->xxorient][0] ,
00169       ORIENT_typestr[daxes->yyorient][0] ,
00170       ORIENT_typestr[daxes->zzorient][0]  ) ;
00171 
00172    LOAD_FVEC3(fv1 , daxes->xxorg , daxes->yyorg , daxes->zzorg) ;
00173    fv1 = THD_3dmm_to_dicomm( dset , fv1 ) ;
00174 
00175    LOAD_FVEC3(fv2 , daxes->xxorg + (daxes->nxx-1)*daxes->xxdel ,
00176                     daxes->yyorg + (daxes->nyy-1)*daxes->yydel ,
00177                     daxes->zzorg + (daxes->nzz-1)*daxes->zzdel  ) ;
00178    fv2 = THD_3dmm_to_dicomm( dset , fv2 ) ;
00179 
00180    if( fv1.xyz[0] > fv2.xyz[0] ) FSWAP( fv1.xyz[0] , fv2.xyz[0] ) ;
00181    if( fv1.xyz[1] > fv2.xyz[1] ) FSWAP( fv1.xyz[1] , fv2.xyz[1] ) ;
00182    if( fv1.xyz[2] > fv2.xyz[2] ) FSWAP( fv1.xyz[2] , fv2.xyz[2] ) ;
00183 
00184    LOAD_FVEC3(fv3 , daxes->xxdel , daxes->yydel , daxes->zzdel) ;
00185    fv3 = THD_3dmm_to_dicomm( dset , fv3 ) ;
00186 
00187    XLAB(xlbot,fv1.xyz[0]) ; YLAB(ylbot,fv1.xyz[1]) ; ZLAB(zlbot,fv1.xyz[2]) ;
00188    XLAB(xltop,fv2.xyz[0]) ; YLAB(yltop,fv2.xyz[1]) ; ZLAB(zltop,fv2.xyz[2]) ;
00189 
00190    n1 = DAXES_NUM(daxes,ORI_R2L_TYPE) ;
00191    n2 = DAXES_NUM(daxes,ORI_A2P_TYPE) ;
00192    n3 = DAXES_NUM(daxes,ORI_I2S_TYPE) ;
00193 
00194    outbuf = THD_zzprintf(outbuf,
00195       "R-to-L extent: %9.3f %s -to- %9.3f %s -step- %9.3f mm [%3d voxels]\n"
00196       "A-to-P extent: %9.3f %s -to- %9.3f %s -step- %9.3f mm [%3d voxels]\n"
00197       "I-to-S extent: %9.3f %s -to- %9.3f %s -step- %9.3f mm [%3d voxels]\n" ,
00198     fv1.xyz[0],xlbot , fv2.xyz[0],xltop , fabs(fv3.xyz[0]) , n1 ,
00199     fv1.xyz[1],ylbot , fv2.xyz[1],yltop , fabs(fv3.xyz[1]) , n2 ,
00200     fv1.xyz[2],zlbot , fv2.xyz[2],zltop , fabs(fv3.xyz[2]) , n3  ) ;
00201 
00202    /*-- 01 Feb 2001: print the center of the dataset as well --*/
00203 
00204    if( verbose > 0 ){
00205     fv1.xyz[0] = 0.5*(fv1.xyz[0]+fv2.xyz[0]) ; XLAB(xlbot,fv1.xyz[0]) ;
00206     fv1.xyz[1] = 0.5*(fv1.xyz[1]+fv2.xyz[1]) ; YLAB(ylbot,fv1.xyz[1]) ;
00207     fv1.xyz[2] = 0.5*(fv1.xyz[2]+fv2.xyz[2]) ; ZLAB(zlbot,fv1.xyz[2]) ;
00208 
00209     outbuf = THD_zzprintf(outbuf,
00210                             "R-to-L center: %9.3f %s\n"
00211                             "A-to-P center: %9.3f %s\n"
00212                             "I-to-S center: %9.3f %s\n" ,
00213                           fv1.xyz[0],xlbot ,
00214                           fv1.xyz[1],ylbot ,
00215                           fv1.xyz[2],zlbot  ) ;
00216    }
00217 
00218    ntimes   = DSET_NUM_TIMES(dset) ;
00219    nval_per = DSET_NVALS_PER_TIME(dset) ;
00220    if( ntimes > 1 ){
00221       outbuf = THD_zzprintf(outbuf,
00222          "Number of time steps = %d  Number of values at each pixel = %d\n",
00223          ntimes , nval_per ) ;
00224 
00225       outbuf = THD_zzprintf(outbuf, "Time step = %.3f%s  Origin = %.3f%s" ,
00226                  dset->taxis->ttdel ,
00227                  UNITS_TYPE_LABEL(dset->taxis->units_type) ,
00228                  dset->taxis->ttorg ,
00229                  UNITS_TYPE_LABEL(dset->taxis->units_type)  ) ;
00230       if( dset->taxis->nsl > 0 )
00231         outbuf = THD_zzprintf(outbuf,"  Number time-offset slices = %d  Thickness = %.3f",
00232                   dset->taxis->nsl , fabs(dset->taxis->dz_sl) ) ;
00233       outbuf = THD_zzprintf(outbuf,"\n") ;
00234 
00235       if( verbose > 0 && dset->taxis->nsl > 0 ){
00236          outbuf = THD_zzprintf(outbuf,"Time-offsets per slice:") ;
00237          for( ival=0 ; ival < dset->taxis->nsl ; ival++ )
00238            outbuf = THD_zzprintf(outbuf, " %.3f" , dset->taxis->toff_sl[ival] ) ;
00239          outbuf = THD_zzprintf(outbuf,"\n") ;
00240       }
00241    } else {
00242       outbuf = THD_zzprintf(outbuf,
00243            "Number of values stored at each pixel = %d\n" , nval_per ) ;
00244    }
00245 
00246 #if 0
00247    if( verbose > 0 && ntimes > 1 ) nval_per = dset->dblk->nvals ;
00248    else                            nval_per = 1 ;                 /* 12 Feb 2002 */
00249 #else
00250    nval_per = dset->dblk->nvals ;
00251    if( verbose < 0 ) nval_per = 1 ;                               /* 27 Mar 2002 */
00252 #endif
00253 
00254    /* print out stuff for each sub-brick */
00255 
00256    for( ival=0 ; ival < nval_per ; ival++ ){
00257 
00258       sprintf( str ,
00259                "  -- At sub-brick #%d '%s' datum type is %s" ,
00260                ival , DSET_BRICK_LAB(dset,ival) ,
00261                MRI_TYPE_name[DSET_BRICK_TYPE(dset,ival)] ) ;
00262       nstr = strlen(str) ;
00263 
00264       tf = DSET_BRICK_FACTOR(dset,ival) ;
00265 
00266       if( ISVALID_STATISTIC(dset->stats) ){
00267 
00268          if( tf != 0.0 ){
00269             sprintf( str+nstr ,
00270                                 ":%13.6g to %13.6g [internal]\n"
00271                     "%*s[*%13.6g] %13.6g to %13.6g [scaled]\n" ,
00272                     dset->stats->bstat[ival].min/tf ,
00273                     dset->stats->bstat[ival].max/tf ,
00274                     nstr-16," " , tf ,
00275                     dset->stats->bstat[ival].min , dset->stats->bstat[ival].max ) ;
00276           } else {
00277             sprintf( str+nstr , ":%13.6g to %13.6g\n" ,
00278                     dset->stats->bstat[ival].min , dset->stats->bstat[ival].max ) ;
00279           }
00280       } else if( tf != 0.0 ){
00281          sprintf( str+nstr , " [*%g]\n",tf) ;
00282       } else {
00283          sprintf( str+nstr , "\n") ;
00284       }
00285       outbuf = THD_zzprintf(outbuf,"%s",str) ;
00286 
00287       /** 30 Nov 1997: print sub-brick stat params **/
00288 
00289       kv = DSET_BRICK_STATCODE(dset,ival) ;
00290       if( FUNC_IS_STAT(kv) ){
00291          outbuf = THD_zzprintf(outbuf,"     statcode = %s",FUNC_prefixstr[kv] ) ;
00292          npar = FUNC_need_stat_aux[kv] ;
00293          if( npar > 0 ){
00294             outbuf = THD_zzprintf(outbuf,";  statpar =") ;
00295             for( kv=0 ; kv < npar ; kv++ )
00296                outbuf = THD_zzprintf(outbuf," %g",DSET_BRICK_STATPAR(dset,ival,kv)) ;
00297          }
00298          outbuf = THD_zzprintf(outbuf,"\n") ;
00299       }
00300 
00301       cpt = DSET_BRICK_KEYWORDS(dset,ival) ;
00302       if( cpt != NULL && cpt[0] != '\0' )
00303          outbuf = THD_zzprintf(outbuf,"     keywords = %s\n",cpt) ;
00304    }
00305 
00306    /** print out dataset global statistical parameters **/
00307 
00308    if( ISFUNC(dset) && FUNC_need_stat_aux[dset->func_type] > 0 ){
00309       outbuf = THD_zzprintf(outbuf,"Auxiliary functional statistical parameters:\n %s\n",
00310              FUNC_label_stat_aux[dset->func_type] ) ;
00311       for( ival=0 ; ival < FUNC_need_stat_aux[dset->func_type] ; ival++ )
00312          outbuf = THD_zzprintf(outbuf," %g",dset->stat_aux[ival]) ;
00313       outbuf = THD_zzprintf(outbuf,"\n") ;
00314    }
00315 
00316    /** If present, print out History **/
00317 
00318    { char *chn ; int j,k ;
00319      chn = tross_Get_History(dset) ;
00320      if( chn != NULL ){
00321        j = strlen(chn) ;
00322        outbuf = THD_zzprintf(outbuf,"\n----- HISTORY -----\n") ;
00323        for( k=0 ; k < j ; k += ZMAX )
00324          outbuf = THD_zzprintf(outbuf,SZMAX,chn+k) ;
00325        free(chn) ;
00326        outbuf = THD_zzprintf(outbuf,"\n") ;
00327      }
00328    }
00329 
00330    /** If present, print out Notes **/
00331 
00332    if( verbose >= 0 ){
00333      ATR_int *notecount;
00334      ATR_string *note;
00335      int num_notes, i, j, num_char , mmm ;
00336      char note_name[20], *chn , *chd ;
00337 
00338      notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00339      if( notecount != NULL ){
00340         num_notes = notecount->in[0] ;
00341         if( verbose == 0 && num_notes > 5 ) num_notes = 5 ;
00342         mmm = (verbose > 0) ? ZMAX : 400 ;
00343         for (i=1; i<= num_notes; i++) {
00344            chn = tross_Get_Note( dset , i ) ;
00345            if( chn != NULL ){
00346               j = strlen(chn) ; if( j > mmm ) chn[mmm] = '\0' ;
00347               chd = tross_Get_Notedate(dset,i) ;
00348               if( chd == NULL ){ chd = AFMALL(char,16) ; strcpy(chd,"no date") ; }
00349               outbuf = THD_zzprintf(outbuf,"\n----- NOTE %d [%s] -----\n%s\n",i,chd,chn) ;
00350               free(chn) ; free(chd) ;
00351            }
00352         }
00353      }
00354    }
00355 
00356    RETURN(outbuf) ;
00357 }

int THD_dataset_mismatch THD_3dim_dataset  ,
THD_3dim_dataset  
 

Definition at line 11 of file thd_mismatch.c.

References THD_3dim_dataset::daxes, ENTRY, ISVALID_DSET, LOAD_FVEC3, MISMATCH_CENTER, MISMATCH_DELTA, MISMATCH_DIMEN, MISMATCH_ORIENT, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, RETURN, SIZE_FVEC3, SUB_FVEC3, THD_dataset_center(), THD_dataxes::xxdel, THD_dataxes::xxorient, THD_dataxes::yydel, THD_dataxes::yyorient, THD_dataxes::zzdel, and THD_dataxes::zzorient.

Referenced by main(), and VL_command_line().

00012 {
00013    THD_dataxes * dax1 , * dax2 ;
00014    THD_fvec3 fv1 , fv2 , dv ;
00015    int code ;
00016    float cd,c1,c2 ;
00017 
00018 ENTRY("THD_dataset_mismatch") ;
00019 
00020    if( !ISVALID_DSET(ds1) || !ISVALID_DSET(ds2) ) RETURN(-1) ;
00021 
00022    dax1 = ds1->daxes ;
00023    dax2 = ds2->daxes ;
00024    code = 0 ;           /* will be return value */
00025 
00026    /* check if the number of voxels in each direction is the same */
00027 
00028    if( dax1->nxx != dax2->nxx ||
00029        dax1->nyy != dax2->nyy ||
00030        dax1->nzz != dax2->nzz   ) code |= MISMATCH_DIMEN ;
00031 
00032    /* check if the grid spacings are the same */
00033 
00034    if( fabs(dax1->xxdel-dax2->xxdel) > 0.01*fabs(dax1->xxdel) ||
00035        fabs(dax1->yydel-dax2->yydel) > 0.01*fabs(dax1->yydel) ||
00036        fabs(dax1->zzdel-dax2->zzdel) > 0.01*fabs(dax1->zzdel)   ) code |= MISMATCH_DELTA ;
00037 
00038    /* check if the orientations are the same */
00039 
00040    if( dax1->xxorient != dax2->xxorient ||
00041        dax1->yyorient != dax2->yyorient ||
00042        dax1->zzorient != dax2->zzorient   ) code |= MISMATCH_ORIENT ;
00043 
00044    /* check if they have the same centers */
00045 
00046    fv1 = THD_dataset_center( ds1 ) ;
00047    fv2 = THD_dataset_center( ds2 ) ;
00048    dv  = SUB_FVEC3(fv1,fv2) ; cd = SIZE_FVEC3(dv) ;
00049 
00050    LOAD_FVEC3(fv1,dax1->xxdel,dax1->yydel,dax1->zzdel) ; c1 = SIZE_FVEC3(fv1) ;
00051    LOAD_FVEC3(fv2,dax2->xxdel,dax2->yydel,dax2->zzdel) ; c2 = SIZE_FVEC3(fv1) ;
00052 
00053    if( cd > 0.1*(c1+c2) ) code |= MISMATCH_CENTER ;
00054 
00055    RETURN(code) ;
00056 }

int THD_dataset_rowfillin THD_3dim_dataset  ,
int   ,
int   ,
int   
 

Definition at line 142 of file thd_rowfillin.c.

References DSET_BRICK_TYPE, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, ENTRY, free, ISVALID_DSET, nz, RETURN, THD_get_dset_row(), THD_get_dset_rowcount(), THD_put_dset_row(), THD_rowfillin_byte(), THD_rowfillin_float(), and THD_rowfillin_short().

Referenced by DRAW_fillin_CB(), and main().

00143 {
00144    int kind , xx,yy,zz , nrow , nx,ny,nz ;
00145    int xtop,ytop,ztop , nff , nfftot=0 ;
00146 
00147 ENTRY("THD_dataset_rowfillin") ;
00148 
00149    if( !ISVALID_DSET(dset)      ||
00150        ival < 0                 ||
00151        ival >= DSET_NVALS(dset) ||
00152        maxgap < 1                 ) RETURN(-1) ;  /* bad things */
00153 
00154    kind = DSET_BRICK_TYPE(dset,ival) ;
00155    if( kind != MRI_short && kind != MRI_byte && kind != MRI_float ) RETURN(-1) ;  /* bad */
00156 
00157    nrow = THD_get_dset_rowcount( dset , dcode ) ;
00158    if( nrow < 1 ) RETURN(-1) ;  /* bad */
00159 
00160    nx = DSET_NX(dset) ;
00161    ny = DSET_NY(dset) ;
00162    nz = DSET_NZ(dset) ;
00163 
00164    xtop = ytop = ztop = 1 ;
00165    switch( dcode ){
00166       case 1: case -1: ytop=ny ; ztop=nz ; break ;
00167       case 2: case -2: xtop=nx ; ztop=nz ; break ;
00168       case 3: case -3: xtop=nx ; ytop=ny ; break ;
00169    }
00170 
00171    switch( kind ){
00172 
00173       case MRI_short:{
00174          short * row ;
00175          for( zz=0 ; zz < ztop ; zz++ )
00176           for( yy=0 ; yy < ytop ; yy++ )
00177             for( xx=0 ; xx < xtop ; xx++ ){
00178                row = THD_get_dset_row( dset,ival , dcode,xx,yy,zz ) ;
00179                nff = THD_rowfillin_short( nrow , row , maxgap ) ;
00180                if( nff > 0 ){
00181                   THD_put_dset_row( dset,ival , dcode,xx,yy,zz , row ) ;
00182                   nfftot += nff ;
00183                }
00184                free(row) ;
00185             }
00186       }
00187       break ;
00188 
00189       case MRI_byte:{
00190          byte * row ;
00191          for( zz=0 ; zz < ztop ; zz++ )
00192           for( yy=0 ; yy < ytop ; yy++ )
00193             for( xx=0 ; xx < xtop ; xx++ ){
00194                row = THD_get_dset_row( dset,ival , dcode,xx,yy,zz ) ;
00195                nff = THD_rowfillin_byte( nrow , row , maxgap ) ;
00196                if( nff > 0 ){
00197                   THD_put_dset_row( dset,ival , dcode,xx,yy,zz , row ) ;
00198                   nfftot += nff ;
00199                }
00200                free(row) ;
00201             }
00202       }
00203       break ;
00204 
00205       case MRI_float:{
00206          float * row ;
00207          for( zz=0 ; zz < ztop ; zz++ )
00208           for( yy=0 ; yy < ytop ; yy++ )
00209             for( xx=0 ; xx < xtop ; xx++ ){
00210                row = THD_get_dset_row( dset,ival , dcode,xx,yy,zz ) ;
00211                nff = THD_rowfillin_float( nrow , row , maxgap ) ;
00212                if( nff > 0 ){
00213                   THD_put_dset_row( dset,ival , dcode,xx,yy,zz , row ) ;
00214                   nfftot += nff ;
00215                }
00216                free(row) ;
00217             }
00218       }
00219       break ;
00220 
00221    }
00222 
00223    RETURN(nfftot) ;
00224 }

NI_group* THD_dataset_to_niml THD_3dim_dataset   dset
 

Put an entire dataset into a single NI group element. -----------------------------------------------------------------------------

Definition at line 487 of file thd_nimlatr.c.

References DSET_NVALS, ENTRY, NI_add_to_group(), NI_rename_group(), RETURN, STATUS, THD_nimlize_dsetatr(), and THD_subbrick_to_niml().

Referenced by AFNI_dataset_to_obj(), main(), and SUMA_SendDset_Afni().

00488 {
00489    NI_element *nel ;
00490    NI_group *ngr ;
00491    int iv ;
00492 
00493 ENTRY("THD_dataset_to_niml") ;
00494 
00495    /* put AFNI dataset attributes into a group */
00496 
00497    ngr = THD_nimlize_dsetatr( dset ) ;
00498    if( ngr == NULL ) RETURN(NULL) ;
00499 
00500    NI_rename_group( ngr , "AFNI_dataset" ) ;
00501 
00502    /* now add a data element for each sub-brick */
00503 
00504    STATUS("adding sub-bricks") ;
00505    for( iv=0 ; iv < DSET_NVALS(dset) ; iv++ ){
00506      nel = THD_subbrick_to_niml( dset , iv , 0 ) ;
00507      if( nel != NULL ) NI_add_to_group( ngr , nel ) ;
00508    }
00509 
00510    RETURN(ngr) ;
00511 }

int THD_dataset_tshift THD_3dim_dataset  ,
int   
 

Definition at line 30 of file thd_tshift.c.

References ADN_none, ADN_nsl, ADN_ntt, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, csfft_nextup_one35(), DSET_load, DSET_LOADED, DSET_mallocize, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_TIMESTEP, EDIT_dset_items(), ENTRY, far, free, ISVALID_DSET, malloc, MRI_FLOAT_PTR, mri_free(), THD_timeaxis::nsl, RETURN, SHIFT_set_method(), SHIFT_two_rows(), THD_3dim_dataset::taxis, THD_extract_series(), THD_insert_series(), THD_linear_detrend(), THD_timeaxis::toff_sl, TS_mode, TS_rlt, TS_slice, TS_tpat, TS_TR, TS_tunits, TS_tzero, UNITS_SEC_TYPE, and THD_timeaxis::units_type.

00031 {
00032    int nzz, ii,jj,kk , ntt,nxx,nyy,nxy , nup , freepat=0 ;
00033    float tomax,tomin , tshift , fmin,fmax , gmin,gmax , f0,f1 , g0,g1 ;
00034    float ffmin,ffmax , ggmin,ggmax ;
00035    MRI_IMAGE * flim , * glim ;
00036    float * far , * gar ;
00037 
00038 ENTRY("THD_dataset_tshift") ;
00039 
00040    /*- extract dataset values, check for errors -*/
00041 
00042    if( !ISVALID_DSET(TS_dset) || ignore < 0 ) RETURN(1) ;
00043 
00044    nxx = DSET_NX(TS_dset) ;                      /* get dimensions */
00045    nyy = DSET_NY(TS_dset) ; nxy = nxx * nyy ;
00046    nzz = DSET_NZ(TS_dset) ;
00047    ntt = DSET_NVALS(TS_dset) ;
00048    if( ignore > ntt-4 ) RETURN(1) ;
00049 
00050    if( DSET_NVALS(TS_dset) < 2 ) RETURN(1) ;
00051    if( TS_slice >= nzz ) RETURN(1) ;
00052 
00053    if( TS_dset->taxis == NULL ){
00054       if( TS_TR == 0.0 || TS_tpat == NULL ) RETURN(1) ;
00055    } else if( TS_tpat == NULL && TS_dset->taxis->toff_sl == NULL ){
00056       RETURN(1) ;
00057    }
00058 
00059    if( TS_TR == 0.0 ){                                    /* set TR from dataset */
00060       TS_TR     = DSET_TIMESTEP(TS_dset) ;
00061       TS_tunits = TS_dset->taxis->units_type ;
00062    }
00063 
00064    if( TS_tpat == NULL ){
00065       if( TS_dset->taxis->nsl < nzz ) RETURN(1) ;
00066       TS_tpat = (float *) malloc( sizeof(float) * nzz ) ;
00067       memcpy( TS_tpat , TS_dset->taxis->toff_sl , sizeof(float)*nzz ) ;
00068       freepat = 1 ;
00069    }
00070 
00071    tomin = WAY_BIG ; tomax = -WAY_BIG ;                      /* check pattern */
00072    for( ii=0 ; ii < nzz ; ii++ ){
00073       if( TS_tpat[ii] > tomax ) tomax = TS_tpat[ii] ;
00074       if( TS_tpat[ii] < tomin ) tomin = TS_tpat[ii] ;
00075    }
00076    if( tomin < 0.0 || tomax > TS_TR ) RETURN(1) ;
00077    else if( tomin >= tomax )          RETURN(1) ;
00078 
00079    if( TS_slice >= 0 && TS_slice < nzz ){                   /* set common time point */
00080       TS_tzero = TS_tpat[TS_slice] ;
00081    } else if( TS_tzero < 0.0 ){
00082       TS_tzero = 0.0 ;
00083       for( ii=0 ; ii < nzz ; ii++ ) TS_tzero += TS_tpat[ii] ;
00084       TS_tzero /= nzz ;
00085    }
00086 
00087    /*- reconfigure the time axis -*/
00088 
00089    DSET_mallocize( TS_dset) ;
00090    DSET_load( TS_dset ) ; if( !DSET_LOADED(TS_dset) ) RETURN(1) ;
00091 
00092    EDIT_dset_items( TS_dset ,
00093                        ADN_ntt    , ntt       ,  /* in case not already set */
00094                        ADN_ttdel  , TS_TR     ,  /* may have changed */
00095                        ADN_tunits , TS_tunits ,  /* may have changed */
00096                        ADN_nsl    , 0         ,  /* will have no offsets when done */
00097                        ADN_ttorg  , 0.0       ,  /* in case not already set */
00098                        ADN_ttdur  , 0.0       ,  /* in case not already set */
00099                     ADN_none ) ;
00100 
00101    /*---- do the temporal shifting! ----*/
00102 
00103    SHIFT_set_method( TS_mode ) ;
00104 
00105    nup = csfft_nextup_one35( ntt+4 ) ;
00106 
00107    for( kk=0 ; kk < nzz ; kk++ ){                            /* loop over slices */
00108 
00109       tshift = (TS_tzero - TS_tpat[kk]) / TS_TR ;  /* rightward fractional shift */
00110 #if 1
00111       tshift = -tshift ;  /* 24 Apr 2003 -- OOG */
00112 #endif
00113 
00114       if( fabs(tshift) < 0.001 ) continue ;                   /* skip this slice */
00115 
00116       for( ii=0 ; ii < nxy ; ii+=2 ){          /* loop over voxel pairs in slice */
00117 
00118          flim = THD_extract_series( ii+kk*nxy , TS_dset , 0 ); /* get this voxel */
00119          far  = MRI_FLOAT_PTR(flim) ;
00120 
00121          if( TS_rlt == 0 ){                             /* range of data: before */
00122             for( ffmin=ffmax=far[ignore],jj=ignore+1 ; jj < ntt ; jj++ ){
00123                     if( far[jj] < ffmin ) ffmin = far[jj] ;
00124                else if( far[jj] > ffmax ) ffmax = far[jj] ;
00125             }
00126          }
00127 
00128          THD_linear_detrend( ntt-ignore , far+ignore , &f0,&f1 ) ;             /* remove trend */
00129 
00130          for( fmin=fmax=far[ignore],jj=ignore+1 ; jj < ntt ; jj++ ){
00131                  if( far[jj] < fmin ) fmin = far[jj] ;   /* range of data: after */
00132             else if( far[jj] > fmax ) fmax = far[jj] ;
00133          }
00134 
00135          if( ii < nxy-1 ){                                       /* get next voxel */
00136             glim = THD_extract_series( ii+kk*nxy+1 , TS_dset , 0 ) ;
00137             gar  = MRI_FLOAT_PTR(glim) ;
00138             if( TS_rlt == 0 ){
00139                for( ggmin=ggmax=gar[ignore],jj=ignore+1 ; jj < ntt ; jj++ ){
00140                        if( gar[jj] < ggmin ) ggmin = gar[jj] ;
00141                   else if( gar[jj] > ggmax ) ggmax = gar[jj] ;
00142                }
00143             }
00144 
00145             THD_linear_detrend( ntt-ignore , gar+ignore , &g0,&g1 ) ;
00146 
00147             for( gmin=gmax=gar[ignore],jj=ignore+1 ; jj < ntt ; jj++ ){
00148                     if( gar[jj] < gmin ) gmin = gar[jj] ;
00149                else if( gar[jj] > gmax ) gmax = gar[jj] ;
00150             }
00151 
00152          } else {
00153             gar  = NULL ;
00154          }
00155 
00156          if( gar != NULL )
00157             SHIFT_two_rows( ntt-ignore,nup, tshift,far+ignore , tshift, gar+ignore ) ;
00158          else
00159             SHIFT_two_rows( ntt-ignore,nup, tshift,far+ignore , tshift, NULL ) ;
00160 
00161          for( jj=ignore ; jj < ntt ; jj++ ){
00162                  if( far[jj] < fmin ) far[jj] = fmin ;           /* clip to input range */
00163             else if( far[jj] > fmax ) far[jj] = fmax ;
00164             switch( TS_rlt ){                                    /* restore trend? */
00165                case 0:
00166                   far[jj] += (f0 + (jj-ignore)*f1) ;
00167                        if( far[jj] < ffmin ) far[jj] = ffmin ;
00168                   else if( far[jj] > ffmax ) far[jj] = ffmax ;
00169                break ;
00170 
00171                case 2:
00172                   far[jj] += f0 ;
00173                break ;
00174             }
00175          }
00176 
00177          if( gar != NULL ){
00178             for( jj=ignore ; jj < ntt ; jj++ ){
00179                     if( gar[jj] < gmin ) gar[jj] = gmin ;
00180                else if( gar[jj] > gmax ) gar[jj] = gmax ;
00181                switch( TS_rlt ){
00182                   case 0:
00183                      gar[jj] += (g0 + (jj-ignore)*g1) ;
00184                           if( gar[jj] < ggmin ) gar[jj] = ggmin ;
00185                      else if( gar[jj] > ggmax ) gar[jj] = ggmax ;
00186                   break ;
00187 
00188                   case 2:
00189                      gar[jj] += g0 ;
00190                   break ;
00191                }
00192             }
00193          }
00194 
00195          /* put back into dataset */
00196 
00197          THD_insert_series( ii+kk*nxy , TS_dset , ntt , MRI_float , far , 0 ) ;
00198          if( gar != NULL )
00199             THD_insert_series( ii+kk*nxy+1 , TS_dset , ntt , MRI_float , gar , 0 ) ;
00200 
00201          /* throw out the trash */
00202 
00203          mri_free(flim) ; if( gar != NULL ) mri_free(glim) ;
00204 
00205       } /* end of loop over voxel pairs */
00206 
00207    } /* end of loop over slices */
00208 
00209    if( freepat ){ free(TS_tpat) ; TS_tpat = NULL ; }  /* resets */
00210    TS_tzero = -1.0 ; TS_TR = 0.0 ; TS_tunits = UNITS_SEC_TYPE ;
00211 
00212    RETURN(0) ;
00213 }

int THD_dataset_zfillin THD_3dim_dataset  ,
int   ,
int   ,
int   
 

Definition at line 40 of file thd_zfillin.c.

References DSET_BRICK_TYPE, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, ENTRY, free, ISVALID_DSET, nz, RETURN, THD_get_dset_row(), THD_get_dset_rowcount(), THD_put_dset_row(), and THD_zfillin_byte().

00041 {
00042    int kind , xx,yy,zz , nrow , nx,ny,nz ;
00043    int xtop,ytop,ztop , nff , nfftot=0 ;
00044 
00045 ENTRY("THD_dataset_rowfillin") ;
00046 
00047    if( !ISVALID_DSET(dset)      ||
00048        ival < 0                 ||
00049        ival >= DSET_NVALS(dset) ||
00050        maxstep < 1                ) RETURN(-1) ;  /* bad things */
00051 
00052    kind = DSET_BRICK_TYPE(dset,ival) ;
00053    if( kind != MRI_byte ) RETURN(-1) ;  /* bad */
00054 
00055    nrow = THD_get_dset_rowcount( dset , dcode ) ;
00056    if( nrow < 1 ) RETURN(-1) ;  /* bad */
00057 
00058    nx = DSET_NX(dset) ;
00059    ny = DSET_NY(dset) ;
00060    nz = DSET_NZ(dset) ;
00061 
00062    xtop = ytop = ztop = 1 ;
00063    switch( dcode ){
00064       case 1: case -1: ytop=ny ; ztop=nz ; break ;
00065       case 2: case -2: xtop=nx ; ztop=nz ; break ;
00066       case 3: case -3: xtop=nx ; ytop=ny ; break ;
00067    }
00068 
00069    switch( kind ){
00070 
00071       case MRI_byte:{
00072          byte * row ;
00073          for( zz=0 ; zz < ztop ; zz++ )
00074           for( yy=0 ; yy < ytop ; yy++ )
00075             for( xx=0 ; xx < xtop ; xx++ ){
00076                row = THD_get_dset_row( dset,ival , dcode,xx,yy,zz ) ;
00077                nff = THD_zfillin_byte( nrow , row , maxstep ) ;
00078                if( nff > 0 ){
00079                   THD_put_dset_row( dset,ival , dcode,xx,yy,zz , row ) ;
00080                   nfftot += nff ;
00081                }
00082                free(row) ;
00083             }
00084       }
00085       break ;
00086 
00087    }
00088 
00089    RETURN(nfftot) ;
00090 }

int THD_datum_constant THD_datablock   blk
 

Check if all sub-bricks have the same datum type. [14 Mar 2002] -------------------------------------------------------------------

Definition at line 26 of file thd_loaddblk.c.

References DBLK_BRICK_TYPE, and THD_datablock::nvals.

Referenced by main(), THD_datablock_from_atr(), and THD_load_datablock().

00027 {
00028    int ibr , dzero , nv=blk->nvals ;
00029    if( nv == 1 ) return 1 ;                /* of course */
00030    dzero = DBLK_BRICK_TYPE(blk,0) ;        /* #0 type */
00031    for( ibr=1 ; ibr < nv ; ibr++ )
00032       if( dzero != DBLK_BRICK_TYPE(blk,ibr) ) return 0 ;
00033    return 1 ;
00034 }

void THD_dblkatr_from_niml NI_group   ngr,
THD_datablock   blk
 

Given a NIML group element, read AFNI attribute elements from it and load these into a datablock. -----------------------------------------------------------------------

Definition at line 121 of file thd_nimlatr.c.

References ATRNAME_IDSTRING, ENTRY, free, malloc, NI_element::name, NI_element_type(), NI_ELEMENT_TYPE, NI_FLOAT, NI_get_attribute(), NI_GROUP_TYPE, NI_INT, NI_STRING, NI_group::part, NI_group::part_num, NI_group::part_typ, STATUS, THD_set_char_atr(), THD_set_float_atr(), THD_set_int_atr(), THD_set_string_atr, THD_unzblock(), NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.

Referenced by THD_niml_to_dataset(), THD_open_nifti(), and THD_read_niml_atr().

00122 {
00123    ATR_any    *atr ;
00124    NI_element *nel ;
00125    int         ip  ;
00126    char       *rhs ;
00127 
00128 ENTRY("THD_dblkatr_from_niml") ;
00129 
00130    if( ngr                  == NULL          ||
00131        NI_element_type(ngr) != NI_GROUP_TYPE ||
00132        blk                  == NULL            ) EXRETURN ;
00133 
00134    /*-- loop over parts and extract data from any '<AFNI_atr ...>' elements --*/
00135 
00136    for( ip=0 ; ip < ngr->part_num ; ip++ ){
00137 
00138      switch( ngr->part_typ[ip] ){
00139 
00140        /*-- a sub-group ==> recursion! --*/
00141 
00142        case NI_GROUP_TYPE:
00143          THD_dblkatr_from_niml( (NI_group *)ngr->part[ip] , blk ) ;
00144        break ;
00145 
00146        /*- data ==> see if is marked as an AFNI_atr and has exactly 1 column
00147                     if so, then extract that column and load into datablock  -*/
00148 
00149        case NI_ELEMENT_TYPE:{ /* data ==> see if is an AFNI attribute */
00150          NI_element *nel = (NI_element *)ngr->part[ip] ;
00151          char       *rhs = NI_get_attribute( nel , "atr_name" ) ;
00152          if( rhs == NULL )
00153                      rhs = NI_get_attribute( nel , "AFNI_name" ) ;
00154 
00155          if( strcasecmp(nel->name,"AFNI_atr") == 0 &&    /* AFNI attribute?   */
00156              nel->vec_num == 1                     &&    /* with some data?   */
00157              nel->vec_len >  0                     &&    /* that is nonempty? */
00158              rhs != NULL                           &&    /* and has a name?   */
00159             *rhs != '\0'                              ){ /* a nonempty name?  */
00160 
00161            STATUS(rhs) ;
00162 
00163            switch( nel->vec_typ[0] ){ /* 3 different data types of attributes */
00164 
00165              /* float attribute: copy 1st column of numbers into AFNI */
00166 
00167              case NI_FLOAT:
00168                THD_set_float_atr( blk , rhs ,
00169                                   nel->vec_len , (float *)nel->vec[0] ) ;
00170              break ;
00171 
00172              /* int attribute: ditto */
00173 
00174              case NI_INT:
00175                THD_set_int_atr( blk , rhs ,
00176                                 nel->vec_len , (int *)nel->vec[0] ) ;
00177              break ;
00178 
00179              /* 02 Jun 2005: if have more than one String here,
00180                              must reassemble them into a single array */
00181 
00182              case NI_STRING:{
00183                char **sar = (char **)nel->vec[0] , *str ;
00184                int nch , nstr=nel->vec_len , istr , lll=0 ;
00185                for( istr=0 ; istr < nstr ; istr++ ) lll += strlen(sar[istr]) ;
00186                str = malloc(lll+4) ; *str = '\0' ;
00187                for( istr=0 ; istr < nstr ; istr++ ) strcat(str,sar[istr]) ;
00188                nch = strlen(str) ;
00189                THD_unzblock( nch+1 , str ) ;  /* re-insert NULs */
00190                THD_set_char_atr( blk , rhs , nch+1 , str ) ;
00191                free(str) ;
00192              }
00193              break ;
00194            }
00195          }
00196        }
00197        break ;
00198      }
00199    } /* end of loop over pieces-parts */
00200 
00201    /* 01 Jun 2005: special case:
00202       reset the IDCODE_STRING attribute if the group element so indicates
00203       (thereby overriding the AFNI_atr element of that name, if was present) */
00204 
00205                      rhs = NI_get_attribute(ngr,"self_idcode") ;
00206    if( rhs == NULL ) rhs = NI_get_attribute(ngr,"AFNI_idcode") ;
00207    if( rhs != NULL && *rhs != '\0' ){
00208      STATUS("reset idcode") ;
00209      THD_set_string_atr( blk , ATRNAME_IDSTRING , rhs ) ;
00210    }
00211 
00212    EXRETURN ;
00213 }

void THD_delete_3dim_dataset THD_3dim_dataset   dset,
Boolean    kill_files
 

30 Nov 1997 *

Definition at line 105 of file thd_delete.c.

References THD_diskptr::brick_name, COMPRESS_unlink(), THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_IS_1D, DSET_IS_3D, DSET_IS_ANALYZE, DSET_IS_CTFMRI, DSET_IS_CTFSAM, DSET_IS_MINC, DSET_IS_NIFTI, DSET_IS_VOLUMES, ENTRY, THD_diskptr::header_name, ISVALID_3DIM_DATASET, ISVALID_TIMEAXIS, KILL_KILL, THD_3dim_dataset::kl, myXtFree, STATUS, THD_3dim_dataset::taxis, THD_delete_datablock(), THD_timeaxis::toff_sl, and unlink.

Referenced by AFNI_andersonville(), AFNI_fimmer_compute(), check_one_output_file(), check_output_file(), check_output_files(), CLUST_main(), copy_dset(), COPY_main(), create_bucket(), cubic_spline(), EDIT_full_copy(), EDIT_main(), fim3d_fimmer_compute(), form_clusters(), get_dimensions(), get_inputs(), get_options(), HEMISUB_main(), IMREG_main(), initialize_program(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), output_results(), output_ts_array(), POWER_main(), PRIC_main(), process_all_datasets(), process_dataset(), r_new_resam_dset(), RCREND_done_CB(), RCREND_reload_dataset(), RCREND_reload_func_dset(), read_afni_data(), REORDER_main(), STAVG_main(), SUMA_VolPar_Attr(), T3D_anatomy_parent_CB(), T3D_geometry_parent_CB(), target_into_dataset(), terminate(), terminate_program(), THD_3dim_from_block(), THD_array_3dim_from_block(), THD_dataset_headname(), THD_init_session(), THD_is_dataset(), THD_open_3dcalc(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), and write_ts_array().

00106 {
00107 ENTRY("THD_delete_3dim_dataset") ;
00108 
00109    if( ! ISVALID_3DIM_DATASET(dset) ) EXRETURN ;
00110 
00111    if( DSET_IS_MINC(dset)    ) kill_files = False ;  /* 29 Oct 2001 */
00112    if( DSET_IS_VOLUMES(dset) ) kill_files = False ;  /* 20 Jun 2002 */
00113    if( DSET_IS_ANALYZE(dset) ) kill_files = False ;  /* 27 Aug 2002 */
00114    if( DSET_IS_1D(dset)      ) kill_files = False ;
00115    if( DSET_IS_3D(dset)      ) kill_files = False ;
00116    if( DSET_IS_CTFMRI(dset)  ) kill_files = False ;
00117    if( DSET_IS_CTFSAM(dset)  ) kill_files = False ;
00118    if( DSET_IS_NIFTI(dset)   ) kill_files = False ;  /* 28 Aug 2003 */
00119 
00120    if( kill_files ){
00121       THD_diskptr *dkptr = dset->dblk->diskptr ;
00122 
00123 STATUS("killing files") ;
00124       unlink( dkptr->header_name ) ;
00125       COMPRESS_unlink(dkptr->brick_name) ;
00126    }
00127 
00128 #ifdef ALLOW_DATASET_VLIST
00129 STATUS("destroy vlist") ;
00130    DESTROY_VLIST(dset->pts) ;
00131 #endif
00132 
00133    if( ISVALID_TIMEAXIS(dset->taxis) ){
00134 STATUS("destroy taxis") ;
00135       myXtFree( dset->taxis->toff_sl ) ;
00136       myXtFree( dset->taxis ) ;
00137    }
00138 
00139    THD_delete_datablock( dset->dblk ) ;
00140 
00141 STATUS("KILL_KILL") ;
00142    KILL_KILL( dset->kl ) ;
00143 
00144    EXRETURN ;
00145 }

void THD_delete_datablock THD_datablock  
 

Definition at line 23 of file thd_delete.c.

References THD_datablock::atr, THD_datablock::brick, THD_datablock::brick_bytes, THD_datablock::brick_fac, THD_datablock::brick_keywords, THD_datablock::brick_lab, THD_datablock::brick_stataux, THD_datablock::brick_statcode, DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DATABLOCK_MEM_SHARED, DBLK_IS_MASTERED, DESTROY_IMARR, THD_datablock::diskptr, ENTRY, FREE_IMARR, ISVALID_DATABLOCK, KILL_KILL, THD_datablock::kl, THD_datablock::locked, THD_datablock::malloc_type, THD_datablock::master_bytes, THD_datablock::master_ival, myXtFree, THD_datablock::nvals, STATUS, THD_count_databricks(), THD_delete_diskptr(), and THD_purge_datablock().

Referenced by THD_delete_3dim_dataset(), THD_init_one_datablock(), and THD_niml_to_dataset().

00024 {
00025    int ibr ;
00026 
00027 ENTRY("THD_delete_datablock") ;
00028 
00029    if( ! ISVALID_DATABLOCK(dblk) ) EXRETURN ;
00030 
00031    /** free the actual brick data (method depends on how it is stored) **/
00032 
00033    if( dblk->brick != NULL ){
00034       dblk->locked = 0 ;
00035 
00036       switch( dblk->malloc_type ){
00037 
00038          default:
00039             STATUS("count bricks") ;
00040             ibr = THD_count_databricks( dblk ) ;
00041             if( ibr > 0 )
00042                fprintf(stderr,
00043                 "** attempt to delete non-NULL unknown type of datablock **\n");
00044 
00045             if( dblk->brick != NULL ) FREE_IMARR( dblk->brick ) ;
00046          break ;
00047 
00048          case DATABLOCK_MEM_MALLOC:
00049          case DATABLOCK_MEM_MMAP:
00050             THD_purge_datablock( dblk , dblk->malloc_type ) ;
00051             DESTROY_IMARR( dblk->brick ) ;
00052          break ;
00053 
00054          case DATABLOCK_MEM_SHARED:   /* 02 May 2003 */
00055            /* ??? */
00056          break ;
00057       }
00058    }
00059 
00060    /** free the other information **/
00061 
00062 STATUS("free brick_ stuff") ;
00063 
00064    myXtFree( dblk->brick_fac ) ;
00065    myXtFree( dblk->brick_bytes ) ;
00066 
00067    /** 30 Nov 1997 **/
00068 
00069    if( dblk->brick_lab != NULL ){
00070       for( ibr=0 ; ibr < dblk->nvals ; ibr++ ) myXtFree( dblk->brick_lab[ibr] ) ;
00071       myXtFree( dblk->brick_lab ) ;
00072    }
00073 
00074    if( dblk->brick_keywords != NULL ){
00075       for( ibr=0 ; ibr < dblk->nvals ; ibr++ ) myXtFree( dblk->brick_keywords[ibr] ) ;
00076       myXtFree( dblk->brick_keywords ) ;
00077    }
00078 
00079    if( dblk->brick_statcode != NULL ) myXtFree( dblk->brick_statcode ) ;
00080    if( dblk->brick_stataux  != NULL ){
00081       for( ibr=0 ; ibr < dblk->nvals ; ibr++ ) myXtFree( dblk->brick_stataux[ibr] ) ;
00082       myXtFree( dblk->brick_stataux ) ;
00083    }
00084 
00085    if( DBLK_IS_MASTERED(dblk) ){       /* 11 Jan 1999 */
00086       myXtFree( dblk->master_ival ) ;
00087       myXtFree( dblk->master_bytes ) ;
00088    }
00089 
00090    THD_delete_diskptr( dblk->diskptr ) ;
00091 
00092 STATUS("KILL_KILL") ;
00093    KILL_KILL( dblk->kl ) ;
00094 
00095 STATUS("free attributes") ;
00096    myXtFree( dblk->atr ) ;    /* not on the kill list */
00097 
00098    EXRETURN ;
00099 }

void THD_delete_diskptr THD_diskptr  
 

Definition at line 14 of file thd_delete.c.

References ISVALID_DISKPTR.

Referenced by THD_delete_datablock().

00015 {
00016    if( ! ISVALID_DISKPTR(dkptr) ) return ;
00017 }

char* THD_deplus_prefix char *    prefix
 

Remove any +???? suffix from a prefix, returning a new one. -- 22 Nov 2002 - RWCox ---------------------------------------------------------------------

Definition at line 806 of file edt_dsetitems.c.

Referenced by EDIT_dset_items().

00807 {
00808    char *newprefix ;
00809    int nn ;
00810 
00811    if( prefix == NULL ) return NULL ;
00812 
00813    nn = strlen(prefix); newprefix = strdup(prefix);
00814 
00815    /* only remove the basic 3: +orig, +acpc +tlrc   17 May 2004 [rickr] */
00816    /* (blame Shruti) */
00817    if( nn > 4 &&   ( (strcmp(newprefix+nn-5,"+orig") == 0) ||
00818                      (strcmp(newprefix+nn-5,"+acpc") == 0) ||
00819                      (strcmp(newprefix+nn-5,"+tlrc") == 0)   ) )
00820       newprefix[nn-5] = '\0' ;
00821 
00822 /* old check
00823        isalpha(newprefix[nn-4]) &&
00824        isalpha(newprefix[nn-3]) &&
00825        isalpha(newprefix[nn-2]) &&
00826        isalpha(newprefix[nn-1])   ) newprefix[nn-5] = '\0' ;
00827 */
00828 
00829    return newprefix ;
00830 }

void THD_dicom_to_coorder THD_coorder  ,
float *   ,
float *   ,
float *   
 

Definition at line 392 of file thd_coords.c.

References THD_coorder::first, THD_coorder::second, THD_coorder::third, THD_coorder::xxsign, THD_coorder::yysign, and THD_coorder::zzsign.

Referenced by main(), and to_3dmm().

00394 {
00395    float xval , yval , zval ;
00396 
00397    if( cord == NULL ) return ;
00398 
00399    /* changes signs first */
00400 
00401    xval = cord->xxsign * (*xx) ;
00402    yval = cord->yysign * (*yy) ;
00403    zval = cord->zzsign * (*zz) ;
00404 
00405    /* scramble order */
00406 
00407    *xx = (cord->first == 0) ? xval
00408         :(cord->first == 1) ? yval : zval ;
00409 
00410    *yy = (cord->second == 0) ? xval
00411         :(cord->second == 1) ? yval : zval ;
00412 
00413    *zz = (cord->third == 0) ? xval
00414         :(cord->third == 1) ? yval : zval ;
00415 
00416    return ;
00417 }

THD_fvec3 THD_dicomm_to_3dmm THD_3dim_dataset  ,
THD_fvec3   
 

Definition at line 212 of file thd_coords.c.

References THD_3dim_dataset::daxes, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, THD_FATAL_ERROR, THD_dataxes::xxorient, THD_fvec3::xyz, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by AFNI_brick_to_mri(), AFNI_crosshair_label(), AFNI_initialize_view(), AFNI_jumpto_dicom(), AFNI_lock_carryout(), AFNI_make_voxwarp(), AFNI_modify_viewing(), AFNI_overlay(), AFNI_setup_viewing(), AFNI_talto_CB(), compute_results(), DRAW_ttatlas_CB(), from_3dmm(), init_seg_endpoints(), main(), process_NIML_Node_ROI(), RCREND_xhair_overlay(), RCREND_xhair_underlay(), SUMA_Find_IminImax(), SUMA_Find_IminImax_Avg(), SUMA_FormAfnidset(), SUMA_make_vnlist(), THD_autonudge(), and xyz_to_ijk().

00214 {
00215    THD_fvec3 imv ;
00216    float xim,yim,zim , xdic,ydic,zdic ;
00217 
00218    xdic = dicv.xyz[0] ; ydic = dicv.xyz[1] ; zdic = dicv.xyz[2] ;
00219 
00220    switch( dset->daxes->xxorient ){
00221       case ORI_R2L_TYPE:
00222       case ORI_L2R_TYPE: xim = xdic ; break ;
00223       case ORI_P2A_TYPE:
00224       case ORI_A2P_TYPE: xim = ydic ; break ;
00225       case ORI_I2S_TYPE:
00226       case ORI_S2I_TYPE: xim = zdic ; break ;
00227 
00228       default: THD_FATAL_ERROR("illegal xxorient code") ;
00229    }
00230 
00231    switch( dset->daxes->yyorient ){
00232       case ORI_R2L_TYPE:
00233       case ORI_L2R_TYPE: yim = xdic ; break ;
00234       case ORI_P2A_TYPE:
00235       case ORI_A2P_TYPE: yim = ydic ; break ;
00236       case ORI_I2S_TYPE:
00237       case ORI_S2I_TYPE: yim = zdic ; break ;
00238 
00239       default: THD_FATAL_ERROR("illegal yyorient code") ;
00240    }
00241 
00242    switch( dset->daxes->zzorient ){
00243       case ORI_R2L_TYPE:
00244       case ORI_L2R_TYPE: zim = xdic ; break ;
00245       case ORI_P2A_TYPE:
00246       case ORI_A2P_TYPE: zim = ydic ; break ;
00247       case ORI_I2S_TYPE:
00248       case ORI_S2I_TYPE: zim = zdic ; break ;
00249 
00250       default: THD_FATAL_ERROR("illegal zzorient code") ;
00251    }
00252 
00253    imv.xyz[0] = xim ; imv.xyz[1] = yim ; imv.xyz[2] = zim ;
00254    return imv ;
00255 }

THD_slist_find THD_dset_in_session int   ,
void *   ,
THD_session  
 

Definition at line 15 of file thd_dsetinsess.c.

References BADFIND, THD_slist_find::dset, THD_slist_find::dset_index, DSET_PREFIX, THD_session::dsset, EQUIV_IDCODES, FIND_IDCODE, FIND_NAME, FIND_PREFIX, FIRST_VIEW_TYPE, THD_3dim_dataset::idcode, ISVALID_SESSION, ISZERO_IDCODE, LAST_VIEW_TYPE, THD_session::num_dsset, THD_3dim_dataset::self_name, and THD_slist_find::view_index.

Referenced by AFNI_drive_switch_anatomy(), AFNI_drive_switch_function(), AFNI_fimmer_compute(), AFNI_rescan_session_NEW(), AFNI_rescan_session_OLD(), DRAW_finalize_dset_CB(), DSET_in_global_session(), process_NIML_Node_ROI(), and THD_dset_in_sessionlist().

00017 {
00018    int id , iv , im ;
00019    THD_3dim_dataset *dset ;
00020    THD_slist_find find ;
00021 
00022    /*-- sanity check --*/
00023 
00024    if( ! ISVALID_SESSION(sess) || target == NULL ){
00025       BADFIND(find) ; return find ;
00026    }
00027 
00028    switch( find_type ){
00029 
00030       /**** search for a name ****/
00031 
00032       case FIND_NAME:{
00033          char *target_name = (char *) target ;
00034          if( strlen(target_name) == 0 ){
00035             BADFIND(find) ; return find ;
00036          }
00037 
00038          for( id=0 ; id < sess->num_dsset ; id++ ){
00039             for( iv=FIRST_VIEW_TYPE ; iv <= LAST_VIEW_TYPE ; iv++ ){
00040                dset = sess->dsset[id][iv] ;
00041 
00042                if( dset != NULL && strcmp(dset->self_name,target_name) == 0 ){
00043                   find.dset = dset ; find.dset_index = id ; find.view_index = iv ;
00044                   return find ;
00045                }
00046             }
00047          }
00048       }
00049       break ;
00050 
00051       /**** search for a prefix ****/
00052 
00053       case FIND_PREFIX:{
00054          char *target_prefix = (char *) target ;
00055          if( strlen(target_prefix) == 0 ){
00056             BADFIND(find) ; return find ;
00057          }
00058 
00059          for( id=0 ; id < sess->num_dsset ; id++ ){
00060             for( iv=FIRST_VIEW_TYPE ; iv <= LAST_VIEW_TYPE ; iv++ ){
00061                dset = sess->dsset[id][iv] ;
00062 
00063                if( dset != NULL && strcmp(DSET_PREFIX(dset),target_prefix) == 0 ){
00064                   find.dset = dset ; find.dset_index = id ; find.view_index = iv ;
00065                   return find ;
00066                }
00067             }
00068          }
00069       }
00070       break ;
00071 
00072       /**** search for an idcode ****/
00073 
00074       case FIND_IDCODE:{
00075          MCW_idcode target_id = *((MCW_idcode *) target) ;
00076 
00077          if( ISZERO_IDCODE(target_id) ){
00078             BADFIND(find) ; return find ;
00079          }
00080 
00081          for( id=0 ; id < sess->num_dsset ; id++ ){
00082             for( iv=FIRST_VIEW_TYPE ; iv <= LAST_VIEW_TYPE ; iv++ ){
00083                dset = sess->dsset[id][iv] ;
00084 
00085                if( dset != NULL && EQUIV_IDCODES(target_id,dset->idcode) ){
00086                   find.dset = dset ; find.dset_index = id ; find.view_index = iv ;
00087                   return find ;
00088                }
00089             }
00090          }
00091       }
00092       break ;
00093 
00094    }  /* end of switch on find_type */
00095 
00096    /*-- fall thru --> not found --*/
00097 
00098    BADFIND(find) ; return find ;
00099 }

THD_slist_find THD_dset_in_sessionlist int   ,
void *   ,
THD_sessionlist  ,
int   
 

Definition at line 16 of file thd_dsetinslist.c.

References BADFIND, THD_slist_find::dset, ISVALID_SESSIONLIST, THD_sessionlist::num_sess, THD_slist_find::sess_index, THD_sessionlist::ssar, and THD_dset_in_session().

Referenced by AFNI_drive_purge_memory(), AFNI_make_descendants_old(), PLUTO_dset_finder(), PLUTO_find_dset(), PLUTO_prefix_ok(), RENAME_main(), and THD_reconcile_parents().

00018 {
00019    int jss ;
00020    THD_slist_find find ;
00021 
00022    /*-- sanity check --*/
00023 
00024    if( ! ISVALID_SESSIONLIST(ssl) || ssl->num_sess <= 0 ){
00025       BADFIND(find) ; return find ;
00026    }
00027 
00028    /* search session # iss first */
00029 
00030    if( iss >=0 && iss < ssl->num_sess ){
00031       find = THD_dset_in_session( find_type,target , ssl->ssar[iss] ) ;
00032       if( find.dset != NULL ){ find.sess_index = iss ; return find ; }
00033    }
00034 
00035    /* search everybody else */
00036 
00037    for( jss=0 ; jss < ssl->num_sess ; jss++ ){
00038       if( jss == iss ) continue ;
00039       find = THD_dset_in_session( find_type,target , ssl->ssar[jss] ) ;
00040       if( find.dset != NULL ){ find.sess_index = jss ; return find ; }
00041    }
00042 
00043    return find ;
00044 }

void THD_edit_dataxes float   ,
THD_dataxes  ,
THD_dataxes  
 

Definition at line 15 of file thd_editdaxes.c.

References ISVALID_DATAXES, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, THD_dataxes::xxdel, THD_dataxes::xxmax, THD_dataxes::xxmin, THD_dataxes::xxorg, THD_dataxes::yydel, THD_dataxes::yymax, THD_dataxes::yymin, THD_dataxes::yyorg, THD_dataxes::zzdel, THD_dataxes::zzmax, THD_dataxes::zzmin, and THD_dataxes::zzorg.

Referenced by AFNI_do_many_writes(), AFNI_setup_viewing(), AFNI_write_dataset_CB(), and main().

00017 {
00018    float lxx , lyy , lzz ;
00019    float rex , rey , rez ;
00020 
00021    if( ! ISVALID_DATAXES(daxes) || ! ISVALID_DATAXES(wod_daxes) ) return ;
00022 
00023    *wod_daxes = *daxes ;       /* copy insides, then edit them */
00024 
00025    if( resam <= 0.0 ) return ; /* error */
00026 
00027    rex = (daxes->xxdel > 0) ? resam : -resam ;  /* signed resampled */
00028    rey = (daxes->yydel > 0) ? resam : -resam ;  /* voxel sizes */
00029    rez = (daxes->zzdel > 0) ? resam : -resam ;
00030 
00031    lxx = daxes->nxx * daxes->xxdel ;    /* signed lengths of data box */
00032    lyy = daxes->nyy * daxes->yydel ;
00033    lzz = daxes->nzz * daxes->zzdel ;
00034 
00035    wod_daxes->nxx = (int)( lxx/rex + 0.499 ) ;  /* new dimensions */
00036    wod_daxes->nyy = (int)( lyy/rey + 0.499 ) ;  /* (will be > 0) */
00037    wod_daxes->nzz = (int)( lzz/rez + 0.499 ) ;
00038 
00039    /* go to old middle, then back out to get new edge */
00040 
00041    wod_daxes->xxorg = daxes->xxorg + 0.5*(lxx - daxes->xxdel)
00042                                    - 0.5*(wod_daxes->nxx - 1)*rex ;
00043 
00044    wod_daxes->yyorg = daxes->yyorg + 0.5*(lyy - daxes->yydel)
00045                                    - 0.5*(wod_daxes->nyy - 1)*rey ;
00046 
00047    wod_daxes->zzorg = daxes->zzorg + 0.5*(lzz - daxes->zzdel)
00048                                    - 0.5*(wod_daxes->nzz - 1)*rez ;
00049 
00050    /* new dimensions of the voxels */
00051 
00052    wod_daxes->xxdel = rex ;
00053    wod_daxes->yydel = rey ;
00054    wod_daxes->zzdel = rez ;
00055 
00056    /* do the bounding box thing again */
00057 
00058    wod_daxes->xxmin = wod_daxes->xxorg ;
00059    wod_daxes->xxmax = wod_daxes->xxorg + (wod_daxes->nxx-1)*wod_daxes->xxdel ;
00060    if( wod_daxes->xxmin > wod_daxes->xxmax ){
00061       float temp = wod_daxes->xxmin ;
00062       wod_daxes->xxmin = wod_daxes->xxmax ; wod_daxes->xxmax = temp ;
00063    }
00064 
00065    wod_daxes->yymin = wod_daxes->yyorg ;
00066    wod_daxes->yymax = wod_daxes->yyorg + (wod_daxes->nyy-1)*wod_daxes->yydel ;
00067    if( wod_daxes->yymin > wod_daxes->yymax ){
00068       float temp = wod_daxes->yymin ;
00069       wod_daxes->yymin = wod_daxes->yymax ; wod_daxes->yymax = temp ;
00070    }
00071 
00072    wod_daxes->zzmin = wod_daxes->zzorg ;
00073    wod_daxes->zzmax = wod_daxes->zzorg + (wod_daxes->nzz-1)*wod_daxes->zzdel ;
00074    if( wod_daxes->zzmin > wod_daxes->zzmax ){
00075       float temp = wod_daxes->zzmin ;
00076       wod_daxes->zzmin = wod_daxes->zzmax ; wod_daxes->zzmax = temp ;
00077    }
00078 
00079 #ifdef EXTEND_BBOX
00080    wod_daxes->xxmin -= 0.5 * wod_daxes->xxdel ;
00081    wod_daxes->xxmax += 0.5 * wod_daxes->xxdel ;
00082    wod_daxes->yymin -= 0.5 * wod_daxes->yydel ;
00083    wod_daxes->yymax += 0.5 * wod_daxes->yydel ;
00084    wod_daxes->zzmin -= 0.5 * wod_daxes->zzdel ;
00085    wod_daxes->zzmax += 0.5 * wod_daxes->zzdel ;
00086 #endif
00087 
00088    return ;
00089 }

int THD_enviro_write_compression void   
 

Definition at line 33 of file thd_writedblk.c.

References COMPRESS_LASTCODE, compress_mode, COMPRESS_NONE, and my_getenv().

Referenced by MAIN_workprocess(), THD_get_write_compression(), and THD_write_datablock().

00034 {
00035    char *hh = my_getenv("AFNI_COMPRESSOR") ;
00036    int ii ;
00037 
00038    compress_mode = COMPRESS_NONE ;
00039    if( hh == NULL ) return COMPRESS_NONE ;
00040 
00041    for( ii=0 ; ii <= COMPRESS_LASTCODE ; ii++ ){
00042       if( strcmp(hh,COMPRESS_enviro[ii]) == 0 ){
00043          compress_mode = ii ;
00044          return ii ;
00045       }
00046    }
00047 
00048    return COMPRESS_NONE ;
00049 }

void THD_enviro_write_order void   
 

Definition at line 67 of file thd_writedblk.c.

References LSB_FIRST_STRING, MSB_FIRST_STRING, my_getenv(), and output_order.

Referenced by THD_get_write_order(), and THD_write_datablock().

00068 {
00069    char *hh = my_getenv("AFNI_BYTEORDER") ;
00070 
00071    if( hh == NULL ){ output_order = -1 ; return ; }
00072 
00073    if( strcmp(hh,LSB_FIRST_STRING) == 0 ){ output_order = LSB_FIRST; return; }
00074    if( strcmp(hh,MSB_FIRST_STRING) == 0 ){ output_order = MSB_FIRST; return; }
00075 
00076    output_order = -1 ; return ;
00077 }

int THD_equiv_files char *    path1,
char *    path2
 

Determine if two filenames are really the same thing.

Definition at line 160 of file thd_filestuff.c.

Referenced by AFNI_append_sessions(), AFNI_finalize_read_sess_CB(), NLFIT_get_many_MODELs(), PLUG_get_many_plugins(), THD_get_many_timeseries(), THD_getpathprogs(), and THD_normalize_flist().

00161 {
00162    static struct stat buf1 , buf2 ; int ii ;
00163 
00164    if( path1 == NULL || path2 == NULL ) return -1 ;
00165    ii = stat( path1 , &buf1 ) ; if( ii != 0 ) return -1 ;
00166    ii = stat( path2 , &buf2 ) ; if( ii != 0 ) return -1 ;
00167 
00168    ii = (buf1.st_dev == buf2.st_dev) && (buf1.st_ino == buf2.st_ino) ;
00169    return ii ;
00170 }

void THD_erase_all_atr THD_datablock   blk
 

actually process element, then exit stage right *

Definition at line 230 of file thd_atr.c.

References THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, ATR_float::fl, ATR_int::in, ISVALID_DATABLOCK, THD_datablock::kl, ATR_float::name, ATR_string::name, ATR_int::name, THD_datablock::natr, SINGLE_KILL, and ATR_any::type.

00231 {
00232    int ia ;
00233    ATR_any *next_atr ;
00234 
00235    if( !ISVALID_DATABLOCK(blk) || blk->natr == 0 || blk->atr == NULL ) return ;
00236 
00237    for( ia=0 ; ia < blk->natr ; ia++ ){
00238       next_atr = blk->atr + ia ;
00239 
00240       switch( next_atr->type ){
00241          case ATR_FLOAT_TYPE:{
00242             ATR_float *aa = (ATR_float *) next_atr ;
00243             SINGLE_KILL( blk->kl , aa->name ) ;
00244             SINGLE_KILL( blk->kl , aa->fl ) ;
00245          }
00246          break ;
00247 
00248          case ATR_STRING_TYPE:{
00249             ATR_string *aa = (ATR_string *) next_atr ;
00250             SINGLE_KILL( blk->kl , aa->name ) ;
00251             SINGLE_KILL( blk->kl , aa->ch ) ;
00252          }
00253          break ;
00254 
00255          case ATR_INT_TYPE:{
00256             ATR_int *aa = (ATR_int *) next_atr ;
00257             SINGLE_KILL( blk->kl , aa->name ) ;
00258             SINGLE_KILL( blk->kl , aa->in ) ;
00259          }
00260          break ;
00261       }
00262 
00263       next_atr->type = ILLEGAL_TYPE ;
00264    }
00265 
00266    blk->natr = 0 ;
00267    return ;
00268 }

void THD_erase_one_atr THD_datablock  ,
char *   
 

Definition at line 274 of file thd_atr.c.

References THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, ATR_float::fl, ATR_int::in, ISVALID_DATABLOCK, THD_datablock::kl, name, ATR_float::name, ATR_string::name, ATR_int::name, THD_datablock::natr, SINGLE_KILL, THD_find_atr(), and ATR_any::type.

Referenced by THD_anonymize_dset(), THD_set_dataset_attributes(), and tross_Delete_Note().

00275 {
00276    ATR_any *next_atr ;
00277 
00278    if( ! ISVALID_DATABLOCK(blk) || name     == NULL ||
00279        blk->natr == 0           || blk->atr == NULL   ) return ;
00280 
00281    next_atr = THD_find_atr( blk , name ) ;
00282 
00283    if( next_atr == NULL ) return ;
00284 
00285    switch( next_atr->type ){
00286       case ATR_FLOAT_TYPE:{
00287          ATR_float *aa = (ATR_float *) next_atr ;
00288          SINGLE_KILL( blk->kl , aa->name ) ;
00289          SINGLE_KILL( blk->kl , aa->fl ) ;
00290       }
00291       break ;
00292 
00293       case ATR_STRING_TYPE:{
00294          ATR_string *aa = (ATR_string *) next_atr ;
00295          SINGLE_KILL( blk->kl , aa->name ) ;
00296          SINGLE_KILL( blk->kl , aa->ch ) ;
00297       }
00298       break ;
00299 
00300       case ATR_INT_TYPE:{
00301          ATR_int *aa = (ATR_int *) next_atr ;
00302          SINGLE_KILL( blk->kl , aa->name ) ;
00303          SINGLE_KILL( blk->kl , aa->in ) ;
00304       }
00305       break ;
00306    }
00307 
00308    next_atr->type = ILLEGAL_TYPE ;
00309    return ;
00310 }

int THD_extract_array int   ,
THD_3dim_dataset  ,
int   ,
void *   
 

Definition at line 71 of file thd_dsetto1D.c.

References AFREALL, CABS, THD_3dim_dataset::dblk, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_NVOX, ENTRY, far, ind, ISVALID_DSET, mri_datum_size(), THD_datablock::nvals, RETURN, THD_need_brick_factor(), and typ.

Referenced by do_xrestore_stuff(), THD_average_timeseries(), THD_extract_series(), THD_mean_brick(), THD_median_brick(), THD_outlier_count(), and THD_rms_brick().

00072 {
00073    MRI_TYPE typ ;
00074    int nv , ival , nb ;
00075    char  *iar ;      /* brick in the input */
00076    float *far=NULL ; /* non-raw output */
00077    static void *tar=NULL ; static int ntar=0 ;
00078 
00079 ENTRY("THD_extract_array") ;
00080 
00081    if( ind < 0             || uar == NULL           ||
00082        !ISVALID_DSET(dset) || ind >= DSET_NVOX(dset)  ) RETURN(-1) ;
00083 
00084    nv  = dset->dblk->nvals ;
00085    iar = DSET_ARRAY(dset,0) ;
00086    if( iar == NULL ){         /* load data from disk? */
00087      DSET_load(dset) ;
00088      iar = DSET_ARRAY(dset,0); if( iar == NULL ) RETURN(-1) ;
00089    }
00090    typ = DSET_BRICK_TYPE(dset,0) ;  /* raw data type */
00091 
00092    /* will extract nb bytes of raw data into array tar */
00093 
00094    nb = mri_datum_size(typ) * (nv+1) ;
00095    if( nb > ntar ){ tar = AFREALL(tar,void *,nb) ; ntar = nb ; }
00096    memset(tar,0,nb) ;
00097 
00098    if( !raw ) far = (float *) uar ;  /* non-raw output */
00099 
00100    switch( typ ){
00101 
00102       default:           /* don't know what to do --> return nada */
00103          RETURN(-1);
00104       break ;
00105 
00106       case MRI_byte:{
00107          byte *ar = (byte *)tar , *bar ;
00108          for( ival=0 ; ival < nv ; ival++ ){
00109             bar = (byte *) DSET_ARRAY(dset,ival) ;
00110             if( bar != NULL ) ar[ival] = bar[ind] ;
00111          }
00112          if( !raw ){
00113             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00114          }
00115       }
00116       break ;
00117 
00118       case MRI_short:{
00119          short *ar = (short *)tar , *bar ;
00120          for( ival=0 ; ival < nv ; ival++ ){
00121             bar = (short *) DSET_ARRAY(dset,ival) ;
00122             if( bar != NULL ) ar[ival] = bar[ind] ;
00123          }
00124          if( !raw ){
00125             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00126          }
00127       }
00128       break ;
00129 
00130       case MRI_float:{
00131          float *ar = (float *)tar , *bar ;
00132          for( ival=0 ; ival < nv ; ival++ ){
00133             bar = (float *) DSET_ARRAY(dset,ival) ;
00134             if( bar != NULL ) ar[ival] = bar[ind] ;
00135          }
00136          if( !raw ){
00137             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00138          }
00139       }
00140       break ;
00141 
00142       case MRI_int:{
00143          int *ar = (int *)tar , *bar ;
00144          for( ival=0 ; ival < nv ; ival++ ){
00145             bar = (int *) DSET_ARRAY(dset,ival) ;
00146             if( bar != NULL ) ar[ival] = bar[ind] ;
00147          }
00148          if( !raw ){
00149             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00150          }
00151       }
00152       break ;
00153 
00154       case MRI_double:{
00155          double *ar = (double *)tar , *bar ;
00156          for( ival=0 ; ival < nv ; ival++ ){
00157             bar = (double *) DSET_ARRAY(dset,ival) ;
00158             if( bar != NULL ) ar[ival] = bar[ind] ;
00159          }
00160          if( !raw ){
00161             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00162          }
00163       }
00164       break ;
00165 
00166       case MRI_complex:{
00167          complex *ar = (complex *)tar , *bar ;
00168          for( ival=0 ; ival < nv ; ival++ ){
00169             bar = (complex *) DSET_ARRAY(dset,ival) ;
00170             if( bar != NULL ) ar[ival] = bar[ind] ;
00171          }
00172          if( !raw ){
00173             for( ival=0 ; ival < nv ; ival++ ) far[ival] = CABS(ar[ival]) ;
00174          }
00175       }
00176       break ;
00177 
00178    }
00179 
00180    if( raw ){ memcpy(uar,tar,nb); RETURN(0); }
00181 
00182    if( THD_need_brick_factor(dset) ){
00183       for( ival=0 ; ival < nv ; ival++ )
00184          if( DSET_BRICK_FACTOR(dset,ival) > 0.0 )
00185            far[ival] *= DSET_BRICK_FACTOR(dset,ival) ;
00186    }
00187 
00188    RETURN(0);
00189 }

THD_string_array* THD_extract_directories THD_string_array  
 

Definition at line 236 of file thd_sarr.c.

References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, INIT_SARR, THD_string_array::num, and THD_is_directory().

Referenced by THD_get_all_subdirs().

00237 {
00238    THD_string_array * star_out ;
00239    int ii ;
00240 
00241    if( star_in == NULL || star_in->num <= 0 ) return NULL ;
00242 
00243    INIT_SARR(star_out) ;
00244 
00245    for( ii=0 ; ii < star_in->num ; ii++ ){
00246       if( THD_is_directory(star_in->ar[ii]) )
00247          ADDTO_SARR( star_out , star_in->ar[ii] ) ;
00248    }
00249 
00250    if( star_out->num == 0 ) DESTROY_SARR(star_out) ;
00251    return star_out ;
00252 }

MRI_IMAGE* THD_extract_float_brick int   ,
THD_3dim_dataset  
 

Definition at line 9 of file thd_dsetto3D.c.

References CABS, DSET_ARRAY, DSET_BRICK, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_NVALS, DSET_NVOX, ENTRY, MRI_FLOAT_PTR, mri_free(), mri_new_conforming, RETURN, and var.

Referenced by main().

00010 {
00011    MRI_IMAGE * im ;
00012    float * var ;
00013    register int ii , nvox ;
00014 
00015 ENTRY("THD_extract_float_brick") ;
00016 
00017    if( iv < 0 || !ISVALID_DSET(dset) || iv >= DSET_NVALS(dset) ) RETURN(NULL);
00018 
00019    im = mri_new_conforming( DSET_BRICK(dset,iv) , MRI_float ) ;
00020    var = MRI_FLOAT_PTR(im) ;
00021    nvox = DSET_NVOX(dset) ;
00022 
00023    /*-- extract/scale brick into var --*/
00024 
00025    switch( DSET_BRICK_TYPE(dset,iv) ){
00026 
00027       default:
00028          fprintf(stderr,"Can't handle sub-bricks of type %s\n",
00029                  MRI_TYPE_name[DSET_BRICK_TYPE(dset,iv)]) ;
00030          mri_free(im) ;
00031       RETURN(NULL) ;
00032 
00033       case MRI_short:{
00034          register short *dar = DSET_ARRAY(dset,iv) ;
00035          register float fac  = DSET_BRICK_FACTOR(dset,iv) ;
00036          if( fac == 0.0 ) fac = 1.0 ;
00037          for( ii=0 ; ii < nvox ; ii++ ) var[ii] = fac*dar[ii] ;
00038       }
00039       break ;
00040 
00041       case MRI_byte:{
00042          register byte  *dar = DSET_ARRAY(dset,iv) ;
00043          register float fac  = DSET_BRICK_FACTOR(dset,iv) ;
00044          if( fac == 0.0 ) fac = 1.0 ;
00045          for( ii=0 ; ii < nvox ; ii++ ) var[ii] = fac*dar[ii] ;
00046       }
00047       break ;
00048 
00049       case MRI_float:{
00050          register float *dar = DSET_ARRAY(dset,iv) ;
00051          register float fac  = DSET_BRICK_FACTOR(dset,iv) ;
00052          if( fac == 0.0 ) fac = 1.0 ;
00053          for( ii=0 ; ii < nvox ; ii++ ) var[ii] = fac*dar[ii] ;
00054       }
00055       break ;
00056 
00057       case MRI_complex:{
00058          register complex *dar = DSET_ARRAY(dset,iv) ;
00059          register float fac    = DSET_BRICK_FACTOR(dset,iv) ;
00060          if( fac == 0.0 ) fac = 1.0 ;
00061          for( ii=0 ; ii < nvox ; ii++ ) var[ii] = fac*CABS(dar[ii]) ;
00062       }
00063       break ;
00064 
00065       case MRI_int:{
00066          register int   *dar = DSET_ARRAY(dset,iv) ;
00067          register float fac  = DSET_BRICK_FACTOR(dset,iv) ;
00068          if( fac == 0.0 ) fac = 1.0 ;
00069          for( ii=0 ; ii < nvox ; ii++ ) var[ii] = fac*dar[ii] ;
00070       }
00071       break ;
00072 
00073       case MRI_double:{
00074          register double *dar = DSET_ARRAY(dset,iv) ;
00075          register float fac   = DSET_BRICK_FACTOR(dset,iv) ;
00076          if( fac == 0.0 ) fac = 1.0 ;
00077          for( ii=0 ; ii < nvox ; ii++ ) var[ii] = fac*dar[ii] ;
00078       }
00079       break ;
00080 
00081       case MRI_rgb:{
00082          register byte *dar = DSET_ARRAY(dset,iv) ;
00083          for( ii=0 ; ii < nvox ; ii++ )
00084             var[ii] = 0.299*dar[3*ii] + 0.587*dar[3*ii+1] + 0.114*dar[3*ii+2] ;
00085       }
00086    }
00087 
00088    RETURN(im) ;
00089 }

MRI_IMARR* THD_extract_many_series int   ,
int *   ,
THD_3dim_dataset  
 

Definition at line 196 of file thd_dsetto1D.c.

References ADDTO_IMARR, THD_datablock::brick_fac, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DESTROY_IMARR, DSET_ARRAY, DSET_BRICK_TYPE, MRI_IMAGE::dx, ENTRY, far, free, IMARR_SUBIMAGE, ind, INIT_IMARR, malloc, MRI_FLOAT_PTR, mri_free(), mri_mult_to_float(), mri_new(), mri_to_float(), THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, RETURN, THD_3dim_dataset::taxis, THD_load_datablock(), THD_need_brick_factor(), THD_timeof(), tt, THD_timeaxis::ttdel, UNITS_MSEC_TYPE, THD_timeaxis::units_type, MRI_IMAGE::xo, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_fimmer_compute(), calculate_results(), and do_xrestore_stuff().

00197 {
00198    MRI_IMARR *imar ; /* output */
00199    MRI_IMAGE *im ;
00200    int nv , ival , kk ;
00201    char *iar ;      /* brick in the input */
00202    float **far ;    /* 27 Feb 2003: ptrs to output */
00203 
00204 ENTRY("THD_extract_many_series") ;
00205 
00206    if( ns <= 0 || ind == NULL | dset == NULL ) RETURN( NULL );
00207 
00208    /* try to load dataset */
00209 
00210    nv  = dset->dblk->nvals ;
00211    iar = DSET_ARRAY(dset,0) ;
00212    if( iar == NULL ){  /* if data needs to be loaded from disk */
00213      (void) THD_load_datablock( dset->dblk ) ;
00214      iar = DSET_ARRAY(dset,0) ;
00215      if( iar == NULL ) RETURN( NULL );
00216    }
00217 
00218    /* create output */
00219 
00220    far = (float **) malloc(sizeof(float *)*ns) ;  /* 27 Feb 2003 */
00221    INIT_IMARR(imar) ;
00222    for( kk=0 ; kk < ns ; kk++ ){
00223      im = mri_new( nv , 1 , MRI_float ) ;  /* N.B.: now does 0 fill */
00224      far[kk] = MRI_FLOAT_PTR(im) ;         /* ptr to kk-th output series */
00225      ADDTO_IMARR(imar,im) ;
00226    }
00227 
00228    /* fill the output */
00229 
00230    switch( DSET_BRICK_TYPE(dset,0) ){
00231 
00232       default:             /* don't know what to do --> return nada */
00233         DESTROY_IMARR(imar) ; free(far) ;
00234         RETURN( NULL );
00235 
00236       case MRI_byte:{
00237         byte * bar ;
00238         for( ival=0 ; ival < nv ; ival++ ){
00239           bar = (byte *) DSET_ARRAY(dset,ival) ;
00240           if( bar != NULL ){
00241             for( kk=0 ; kk < ns ; kk++ ){
00242               far[kk][ival] = (float)bar[ind[kk]] ;
00243             }
00244           }
00245         }
00246       }
00247       break ;
00248 
00249       case MRI_short:{
00250         short * bar ;
00251         for( ival=0 ; ival < nv ; ival++ ){
00252           bar = (short *) DSET_ARRAY(dset,ival) ;
00253           if( bar != NULL ){
00254             for( kk=0 ; kk < ns ; kk++ ){
00255               far[kk][ival] = (float)bar[ind[kk]] ;
00256             }
00257           }
00258         }
00259       }
00260       break ;
00261 
00262       case MRI_float:{
00263          float * bar ;
00264          for( ival=0 ; ival < nv ; ival++ ){
00265             bar = (float *) DSET_ARRAY(dset,ival) ;
00266             if( bar != NULL ){
00267               for( kk=0 ; kk < ns ; kk++ ){
00268                  far[kk][ival] = bar[ind[kk]] ;
00269               }
00270             }
00271          }
00272       }
00273       break ;
00274 
00275       case MRI_int:{
00276          int * bar ;
00277          for( ival=0 ; ival < nv ; ival++ ){
00278             bar = (int *) DSET_ARRAY(dset,ival) ;
00279             if( bar != NULL ){
00280               for( kk=0 ; kk < ns ; kk++ ){
00281                  far[kk][ival] = bar[ind[kk]] ;
00282               }
00283             }
00284          }
00285       }
00286       break ;
00287 
00288       case MRI_double:{
00289          double * bar ;
00290          for( ival=0 ; ival < nv ; ival++ ){
00291             bar = (double *) DSET_ARRAY(dset,ival) ;
00292             if( bar != NULL ){
00293               for( kk=0 ; kk < ns ; kk++ ){
00294                  far[kk][ival] = (float)bar[ind[kk]] ;
00295               }
00296             }
00297          }
00298       }
00299       break ;
00300 
00301       case MRI_complex:{
00302          complex * bar ;
00303          for( ival=0 ; ival < nv ; ival++ ){
00304             bar = (complex *) DSET_ARRAY(dset,ival) ;
00305             if( bar != NULL ){
00306               for( kk=0 ; kk < ns ; kk++ ){
00307                  far[kk][ival] = bar[ind[kk]].r ;
00308               }
00309             }
00310          }
00311       }
00312       break ;
00313 
00314    }
00315 
00316    /* scale outputs, if needed */
00317 
00318    if( THD_need_brick_factor(dset) ){
00319       MRI_IMAGE * qim ;
00320       for( kk=0 ; kk < ns ; kk++ ){
00321          im  = IMARR_SUBIMAGE(imar,kk) ;
00322          qim = mri_mult_to_float( dset->dblk->brick_fac , im ) ;
00323          mri_free(im) ;
00324          IMARR_SUBIMAGE(imar,kk) = qim ;
00325       }
00326    }
00327 
00328 #if 0  /* 27 Feb 2003 */
00329    /* convert to floats, if needed */
00330 
00331    if( IMARR_SUBIMAGE(imar,0)->kind != MRI_float ){
00332       MRI_IMAGE * qim ;
00333       for( kk=0 ; kk < ns ; kk++ ){
00334          im  = IMARR_SUBIMAGE(imar,kk) ;
00335          qim = mri_to_float( im ) ;
00336          mri_free(im) ;
00337          IMARR_SUBIMAGE(imar,kk) = qim ;
00338       }
00339    }
00340 #endif
00341 
00342    /* add time axis stuff to output images, if present */
00343 
00344    if( dset->taxis != NULL ){
00345       float zz , tt ;
00346       int kz ;
00347 
00348       for( kk=0 ; kk < ns ; kk++ ){
00349          kz = ind[kk] / ( dset->daxes->nxx * dset->daxes->nyy ) ;
00350          zz = dset->daxes->zzorg + kz * dset->daxes->zzdel ;
00351          tt = THD_timeof( 0 , zz , dset->taxis ) ;
00352          im = IMARR_SUBIMAGE(imar,kk) ;
00353          im->xo = tt ; im->dx = dset->taxis->ttdel ;   /* origin and delta */
00354          if( dset->taxis->units_type == UNITS_MSEC_TYPE ){ /* convert to sec */
00355             im->xo *= 0.001 ; im->dx *= 0.001 ;
00356          }
00357       }
00358    } else {
00359       for( kk=0 ; kk < ns ; kk++ ){
00360          im = IMARR_SUBIMAGE(imar,kk) ;
00361          im->xo = 0.0 ; im->dx = 1.0 ;
00362       }
00363    }
00364 
00365    free(far) ; RETURN(imar);
00366 }

THD_string_array* THD_extract_regular_files THD_string_array   star_in
 

must want deeper levels *

Definition at line 213 of file thd_sarr.c.

References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, INIT_SARR, THD_string_array::num, and THD_is_file().

Referenced by NLFIT_get_all_MODELs(), PLUG_get_all_plugins(), THD_get_all_executables(), THD_get_all_timeseries(), and THD_init_alldir_datablocks().

00214 {
00215    THD_string_array * star_out ;
00216    int ii ;
00217 
00218    if( star_in == NULL || star_in->num <= 0 ) return NULL ;
00219 
00220    INIT_SARR(star_out) ;
00221 
00222    for( ii=0 ; ii < star_in->num ; ii++ ){
00223       if( THD_is_file(star_in->ar[ii]) )
00224          ADDTO_SARR( star_out , star_in->ar[ii] ) ;
00225    }
00226 
00227    if( star_out->num == 0 ) DESTROY_SARR(star_out) ;
00228    return star_out ;
00229 }

MRI_IMAGE* THD_extract_series int   ,
THD_3dim_dataset  ,
int   
 

Definition at line 23 of file thd_dsetto1D.c.

References THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DSET_BRICK_TYPE, MRI_IMAGE::dx, ENTRY, ind, ISVALID_DSET, mri_data_pointer(), mri_free(), mri_new(), THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, RETURN, THD_3dim_dataset::taxis, THD_extract_array(), THD_timeof(), tt, THD_timeaxis::ttdel, typ, UNITS_MSEC_TYPE, THD_timeaxis::units_type, MRI_IMAGE::xo, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by DSET2_func(), DSETN_func(), extract_ts_array(), init_floatvector_array(), main(), read_ts_array(), segment_imarr(), and THD_dataset_tshift().

00024 {
00025    int nv , typ , ii ;
00026    MRI_IMAGE *im ;
00027    void *imar ;
00028 
00029 ENTRY("THD_extract_series") ;
00030 
00031    if( !ISVALID_DSET(dset) ) RETURN(NULL) ;
00032 
00033    nv  = dset->dblk->nvals ;
00034    if( raw ) typ = DSET_BRICK_TYPE(dset,0) ;  /* type of output array */
00035    else      typ = MRI_float ;
00036 
00037    im   = mri_new( nv , 1 , typ ) ;           /* output image */
00038    imar = mri_data_pointer(im) ;
00039 
00040    ii = THD_extract_array( ind , dset , raw , imar ) ; /* get data */
00041 
00042    if( ii != 0 ){ mri_free(im) ; RETURN(NULL) ; }      /* bad */
00043 
00044    if( dset->taxis != NULL ){  /* 21 Oct 1996 */
00045       float zz , tt ;
00046       int kz = ind / ( dset->daxes->nxx * dset->daxes->nyy ) ;
00047 
00048       zz = dset->daxes->zzorg + kz * dset->daxes->zzdel ;
00049       tt = THD_timeof( 0 , zz , dset->taxis ) ;
00050 
00051       im->xo = tt ; im->dx = dset->taxis->ttdel ;   /* origin and delta */
00052 
00053       if( dset->taxis->units_type == UNITS_MSEC_TYPE ){ /* convert to sec */
00054          im->xo *= 0.001 ; im->dx *= 0.001 ;
00055       }
00056    } else {
00057       im->xo = 0.0 ; im->dx = 1.0 ;  /* 08 Nov 1996 */
00058    }
00059 
00060    RETURN(im) ;
00061 }

THD_fvec3 THD_fdfind_to_3dfind FD_brick  ,
THD_fvec3   
 

Definition at line 291 of file thd_coords.c.

References FD_brick::a123, abs, THD_ivec3::ijk, FD_brick::sxyz, and THD_fvec3::xyz.

00292 {
00293    THD_fvec3 id ;
00294    int qq , ax ;
00295 
00296    for( qq=0 ; qq < 3 ; qq++ ){
00297       ax = abs( br->a123.ijk[qq] ) - 1 ;   /* 0,1,2, for x,y,z */
00298 
00299       if( br->a123.ijk[qq] > 0 ) id.xyz[ax] = ib.xyz[qq] ;
00300       else                       id.xyz[ax] = br->sxyz.ijk[ax] - ib.xyz[qq];
00301    }
00302 
00303    return id ;
00304 }

THD_ivec3 THD_fdind_to_3dind FD_brick  ,
THD_ivec3   
 

Definition at line 259 of file thd_coords.c.

References FD_brick::a123, abs, THD_ivec3::ijk, and FD_brick::sxyz.

Referenced by AFNI_brick_to_mri(), AFNI_gra_send_CB(), AFNI_seq_send_CB(), FD_brick_to_series(), GRA_drawing_EV(), GRA_handle_keypress(), plot_graphs(), and redraw_graph().

00260 {
00261    THD_ivec3 id ;
00262    int qq , ax ;
00263 
00264    for( qq=0 ; qq < 3 ; qq++ ){
00265       ax = abs( br->a123.ijk[qq] ) - 1 ;   /* 0,1,2, for x,y,z */
00266 
00267       if( br->a123.ijk[qq] > 0 ) id.ijk[ax] = ib.ijk[qq] ;
00268       else                       id.ijk[ax] = br->sxyz.ijk[ax] - ib.ijk[qq];
00269    }
00270 
00271    return id ;
00272 }

MRI_IMAGE* THD_fetch_1D char *    url
 

perhaps need to swap bytes *

Definition at line 116 of file thd_fetchdset.c.

References ENTRY, far, free, mri_add_name(), MRI_FLOAT_PTR, mri_read_1D(), NI_read_URL_tmpdir(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, and unlink.

Referenced by THD_fetch_many_datasets().

00117 {
00118    char *fname ;
00119    int nhp , ii ;
00120    MRI_IMAGE * flim ;
00121    float * far ;
00122 
00123 ENTRY("THD_fetch_1D") ;
00124 
00125    if( url == NULL || url[0] == '\0' ) RETURN(NULL) ;
00126 
00127    fprintf(stderr,"\n+++ Trying to fetch %s",url) ;
00128    nhp = NI_read_URL_tmpdir( url , &fname ) ;
00129    if( nhp <= 0 ){ fprintf(stderr," **FAILED\n"); RETURN(NULL); }
00130    fprintf(stderr,": %d bytes read",nhp) ;
00131    flim = mri_read_1D(fname) ; unlink(fname) ; free(fname) ;
00132    if( flim != NULL ){
00133       mri_add_name( url , flim ) ; fprintf(stderr,": %dx%d file\n",flim->nx,flim->ny) ;
00134       far = MRI_FLOAT_PTR(flim) ;
00135       for( ii=0 ; ii < flim->nvox ; ii++ )
00136          if( fabs(far[ii]) >= 33333.0 ) far[ii] = WAY_BIG ;
00137    } else {
00138       fprintf(stderr," **Can't read as a .1D file!\n") ;
00139    }
00140    RETURN(flim) ;
00141 }

THD_3dim_dataset* THD_fetch_dataset char *   
 

Definition at line 7 of file thd_fetchdset.c.

References AFMALL, THD_diskptr::byte_order, THD_3dim_dataset::dblk, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_NVOX, DBLK_BRICK_TYPE, THD_datablock::diskptr, DSET_delete, DSET_IS_MINC, DSET_IS_NIFTI, DSET_IS_VOLUMES, DSET_load, DSET_mallocize, DSET_NVALS, DSET_superlock, ENTRY, free, iochan_sleep(), mri_fix_data_pointer(), mri_short_order(), mri_swap2(), mri_swap4(), NI_read_URL(), NI_read_URL_tmpdir(), RETURN, STRING_HAS_SUFFIX, THD_allow_empty_dataset(), THD_open_one_dataset(), THD_datablock::total_bytes, and unlink.

Referenced by AFNI_finalize_read_Web_CB(), THD_fetch_many_datasets(), and THD_open_dataset().

00008 {
00009    char *cp,*hp,*bp , *thp ;
00010    int nhp,nbp , iv ;
00011    THD_3dim_dataset * dset ;
00012    int native_order ;
00013 
00014 ENTRY("THD_fetch_dset") ;
00015 
00016    if( url == NULL || url[0] == '\0' ) RETURN(NULL) ;
00017 
00018    if( STRING_HAS_SUFFIX(url,".hdr") ) RETURN(NULL) ;  /* 27 Aug 2002 */
00019 
00020    /*** do we have to add .HEAD? ***/
00021 
00022    hp = AFMALL(char, sizeof(char)*(strlen(url)+32)) ; strcpy(hp,url) ;
00023    cp = strstr(hp,".HEAD") ;
00024    if( cp == NULL                       &&
00025        !STRING_HAS_SUFFIX(hp,".nii")    &&  /* 28 Aug 2003 */
00026        !STRING_HAS_SUFFIX(hp,".nii.gz") &&  /* 06 Apr 2005 */
00027        !STRING_HAS_SUFFIX(hp,".mnc")    &&
00028        !STRING_HAS_SUFFIX(hp,".mnc.gz")   ) strcat(hp,".HEAD") ;
00029 
00030    /*** read the .HEAD file to a temporary file ***/
00031 
00032    fprintf(stderr,"\n+++ Trying to fetch %s",hp) ;
00033    nhp = NI_read_URL_tmpdir( hp , &thp ) ;
00034    if( nhp <= 0 ){ fprintf(stderr," **FAILED\n"); free(hp); RETURN(NULL); }
00035 
00036    /*** try to open it as a dataset header ***/
00037 
00038    fprintf(stderr,": %d bytes read\n ++ Trying to initialize dataset %s\n",nhp,thp) ;
00039    THD_allow_empty_dataset(1) ;
00040    dset = THD_open_one_dataset(thp) ;
00041    if( DSET_IS_MINC(dset) || DSET_IS_NIFTI(dset) ) DSET_load(dset) ;  /* 29 Oct 2001 */
00042    THD_allow_empty_dataset(0) ;
00043    unlink(thp) ; free(thp) ;
00044    if( dset == NULL ){ fprintf(stderr," ** Can't decode %s\n",hp); free(hp); RETURN(NULL); }
00045 
00046    if( DSET_IS_VOLUMES(dset) ){  /* 20 Jun 2002 */
00047      fprintf(stderr," ** Can't load %s by volumes!\n",hp); free(hp);
00048      DSET_delete(dset); RETURN(NULL);
00049    }
00050 
00051    DSET_superlock(dset) ;  /* don't let be deleted from memory */
00052    if( DSET_IS_MINC(dset) || DSET_IS_NIFTI(dset) ) RETURN(dset) ;  /* 29 Oct 2001 */
00053    DSET_mallocize(dset) ;
00054 
00055    /*** try to read the .BRIK or .BRIK.gz file into memory ***/
00056 
00057    strcpy( hp+(strlen(hp)-5) , ".BRIK.gz" ) ;
00058    fprintf(stderr," ++ Trying to fetch %s",hp) ; iochan_sleep(100) ;
00059    nbp = NI_read_URL( hp , &bp ) ;
00060    if( nbp <= 0 ){
00061       iv = strlen(hp) ; hp[iv-3] = '\0' ; /* remove the .gz and try again */
00062       fprintf(stderr," ** FAILED!\n ++ Trying to fetch %s",hp) ; iochan_sleep(100) ;
00063       nbp = NI_read_URL( hp , &bp ) ;
00064       if( nbp <= 0 ){
00065          fprintf(stderr," ** FAILED\n");
00066          free(hp); DSET_delete(dset); RETURN(NULL);
00067       }
00068    }
00069    if( nbp < dset->dblk->total_bytes ){
00070       fprintf(stderr,"\n ** Got %s but only had %d bytes, but needed %lld\n",
00071               hp,nbp,dset->dblk->total_bytes) ;
00072       free(bp) ; free(hp) ; DSET_delete(dset) ; RETURN(NULL) ;
00073    }
00074    fprintf(stderr,": %d bytes read\n",nbp) ;
00075 
00076    /** now have data: build pointers, load bricks, return **/
00077 
00078    for( iv=0 ; iv < DSET_NVALS(dset) ; iv++ ){
00079       mri_fix_data_pointer( bp , DBLK_BRICK(dset->dblk,iv) ) ;
00080       bp += DBLK_BRICK_BYTES(dset->dblk,iv) ;
00081    }
00082 
00083    /** perhaps need to swap bytes **/
00084 
00085    native_order = mri_short_order() ;
00086 
00087    if( dset->dblk->diskptr->byte_order <= 0 )
00088       dset->dblk->diskptr->byte_order = native_order ;
00089 
00090    if( dset->dblk->diskptr->byte_order != native_order ){
00091       for( iv=0 ; iv < DSET_NVALS(dset) ; iv++ ){
00092          switch( DBLK_BRICK_TYPE(dset->dblk,iv) ){
00093             case MRI_short:
00094                mri_swap2( DBLK_BRICK_NVOX(dset->dblk,iv) , DBLK_ARRAY(dset->dblk,iv) ) ;
00095             break ;
00096 
00097             case MRI_complex:  /* 14 Sep 1999: swap complex also! */
00098                mri_swap4( 2*DBLK_BRICK_NVOX(dset->dblk,iv), DBLK_ARRAY(dset->dblk,iv)) ;
00099             break ;
00100 
00101             case MRI_float:
00102             case MRI_int:
00103                mri_swap4( DBLK_BRICK_NVOX(dset->dblk,iv) , DBLK_ARRAY(dset->dblk,iv) ) ;
00104             break ;
00105          }
00106       }
00107    }
00108 
00109    free(hp) ; RETURN(dset) ;
00110 }

XtPointer_array* THD_fetch_many_datasets char *   
 

Definition at line 148 of file thd_fetchdset.c.

References ADDTO_XTARR, ENTRY, free, FREE_XTARR, i1, i2, IC_DSET, IC_FLIM, INIT_XTARR, iochan_sleep(), ISVALID_DSET, malloc, NI_read_URL(), XtPointer_array::num, RETURN, THD_fetch_1D(), THD_fetch_dataset(), THD_trailname(), XTARR_IC, and XTARR_NUM.

Referenced by AFNI_finalize_read_Web_CB(), and AFNI_read_inputs().

00149 {
00150    XtPointer_array * dsar ;
00151    int nlist , i1,i2 , nh , ll , nx ;
00152    char * list ;
00153    char * tnam , * hnam , * dnam ;
00154    THD_3dim_dataset * dset ;
00155 
00156 ENTRY("THD_fetch_many_datasets") ;
00157 
00158    if( url == NULL || url[0] == '\0' ) RETURN(NULL) ;
00159 
00160    /* make hnam be the URL directory (without the trailing filename) */
00161 
00162    hnam = (char *) malloc(sizeof(char)*(strlen(url)+16)) ;
00163    strcpy(hnam,url) ;
00164    tnam = THD_trailname( hnam , 0 ) ;                /* start of trailing name */
00165    if( tnam == hnam ){ free(hnam); RETURN(NULL); }
00166    *tnam = '\0' ; nh = strlen(hnam) ;                /* cut trailing name off */
00167 
00168    /* get the list of filenames */
00169 
00170    fprintf(stderr,"\n+++ Trying to fetch %s",url) ;
00171    nlist = NI_read_URL( url , &list ) ;
00172    if( nlist <= 0 ){
00173       fprintf(stderr," **FAILED\n"); free(hnam); RETURN(NULL);
00174    }
00175    fprintf(stderr,": %d bytes read\n",nlist) ;
00176 
00177    /* scan from list[i1] forward, looking for filenames to fetch */
00178 
00179    i1 = 0 ; INIT_XTARR(dsar) ;
00180 
00181    while( i1 < nlist ){
00182 
00183       for( ; i1 < nlist && isspace(list[i1]) ; i1++ ) ; /* skip whitespace */
00184       if( i1 >= nlist ) break ;
00185       if( list[i1] == '#' ){ /* skip comment line */
00186          for( ; i1 < nlist && list[i1] != '\n' ; i1++ ) ; /* skip to EOL */
00187          continue ;                                       /* restart while loop */
00188       }
00189 
00190       for( i2=i1+1 ; i2 < nlist && !isspace(list[i2]) ; i2++ ) ; /* skip to next blank */
00191 
00192       /* filename is list[i1..i2-1] */
00193 
00194       dnam = (char *)malloc(sizeof(char)*(nh+i2-i1+16)) ;  /* space for new URL */
00195       strcpy(dnam,hnam);                                   /* put header on */
00196       memcpy(dnam+nh,list+i1,i2-i1);                       /* put filename on */
00197       dnam[nh+i2-i1] = '\0';                               /* and end it */
00198 
00199       iochan_sleep(100) ;
00200       ll = strlen(dnam)-3 ; if( ll < 1 ) continue ;
00201       if( strcmp(dnam+ll,".1D")==0 ||
00202           strcmp(dnam+ll,"1Dx")==0 ||
00203           strcmp(dnam+ll,"1Dv")==0   ){                      /** get a 1D file **/
00204 
00205          MRI_IMAGE * im = THD_fetch_1D( dnam ) ;
00206 
00207          if( im != NULL ){
00208             ADDTO_XTARR(dsar,im) ;
00209             nx = XTARR_NUM(dsar)-1 ;
00210             XTARR_IC(dsar,nx) = IC_FLIM ;
00211          }
00212 
00213       } else {                                                /** get a dataset **/
00214          dset = THD_fetch_dataset( dnam ) ;
00215          if( ISVALID_DSET(dset) ){
00216             ADDTO_XTARR(dsar,dset) ;
00217             nx = XTARR_NUM(dsar)-1 ;
00218             XTARR_IC(dsar,nx) = IC_DSET ;
00219          }
00220       }
00221       free(dnam) ;
00222 
00223       i1 = i2 ; /* restart scan at next position */
00224    }
00225 
00226    /* toss the trash and go home */
00227 
00228    free(list) ; free(hnam) ;
00229    if( dsar->num == 0 ){ FREE_XTARR(dsar) ; dsar = NULL ; }
00230    RETURN(dsar) ;
00231 }

void THD_fftshift THD_3dim_dataset  ,
float   ,
float   ,
float   ,
int   
 

time_t THD_file_mtime char *    pathname
 

Return the time at which the file was last modified.

Definition at line 467 of file Ifile.c.

00468 {
00469    static struct stat buf ; int ii ;
00470 
00471    if( pathname == NULL ) return 0 ;
00472    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00473    return buf.st_mtime ;
00474 }

int THD_filename_ok char *    name
 

Check if a filename is OK - that is, has no crummy characters.

The filename can have a '/' in it. To insist that there be not '/', use THD_filename_pure(). The list of crummy characters can be inferred from the source code.

Definition at line 220 of file thd_filestuff.c.

References name.

Referenced by AFNI_finalize_saveim_CB(), AFNI_finalize_write_palette_CB(), AFNI_finalsave_layout_CB(), AFNI_process_setup(), CL_read_opts(), init_options(), ISQ_snapfile(), main(), multivector_write(), PRIC_main(), RCREND_finalize_saveim_CB(), RCREND_save_many_CB(), RCREND_save_this_CB(), REND_finalize_saveim_CB(), REND_save_many_CB(), REND_save_this_CB(), SUMA_AFNI_Extract_Colors(), SUMA_AfniPrefix(), SUMA_BrainVoyager_Read_vmr(), SUMA_OpenDX_Read_CruiseVolHead(), T3D_initialize_user_data(), TAG_write_CB(), THD_filename_pure(), THD_mkdir(), THD_warp3D(), THD_write_minc(), THD_write_nifti(), THD_zeropad(), tross_commandline(), validate_datasets(), VOLREG_main(), and WINsorize().

00221 {
00222    int ll , ii ;
00223 
00224    if( name == NULL ) return 0 ;
00225    ll = strlen( name ) ; if( ll == 0 ) return 0 ;
00226 
00227    for( ii=0 ; ii < ll ; ii++ )
00228       if( iscntrl(name[ii]) || isspace(name[ii]) ||
00229                                name[ii] == ';'   ||
00230           name[ii] == '*'   || name[ii] == '?'   ||
00231           name[ii] == '&'   || name[ii] == '|'   ||
00232           name[ii] == '"'   || name[ii] == '>'   ||
00233           name[ii] == '<'   || name[ii] == '\''  ||
00234           name[ii] == '['   || name[ii] == ']'   ||
00235           name[ii] == '('   || name[ii] == ')'   ||
00236           name[ii] == '{'   || name[ii] == '}'   ||
00237           name[ii] == '!'   || (name[ii] & 128) != 0 ) return 0 ;
00238 
00239    return 1 ;
00240 }

int THD_filename_pure char *    name
 

Check if a filename is pure - no crummy characters, no '/'.

Definition at line 245 of file thd_filestuff.c.

References name, and THD_filename_ok().

Referenced by AFNI_process_environ(), AFNI_process_setup(), main(), PLUGIN_init(), process_NIML_Node_ROI(), RT_check_info(), RT_main(), RT_process_info(), and SUMA_AFNI_Extract_Colors().

00246 {
00247    int ii ;
00248 
00249    ii = THD_filename_ok( name ) ;
00250    if( ii ) ii = (strstr(name,"/") == NULL) ;
00251    return ii ;
00252 }

long THD_filesize char *    pathname
 

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

Definition at line 499 of file Ifile.c.

00500 {
00501    static struct stat buf ; int ii ;
00502 
00503    if( pathname == NULL ) return -1 ;
00504    ii = stat( pathname , &buf ) ; if( ii != 0 ) return -1 ;
00505    return buf.st_size ;
00506 }

ATR_any* THD_find_atr THD_datablock  ,
char *   
 

Definition at line 317 of file thd_atr.c.

References THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ENTRY, ISVALID_DATABLOCK, name, ATR_float::name, ATR_string::name, ATR_int::name, THD_datablock::natr, RETURN, THD_FATAL_ERROR, and ATR_any::type.

Referenced by main(), THD_erase_one_atr(), THD_find_float_atr(), THD_find_int_atr(), THD_find_string_atr(), and THD_set_atr().

00318 {
00319    int ia ;
00320 
00321 ENTRY("THD_find_atr") ;
00322 
00323    if( ! ISVALID_DATABLOCK(blk) )
00324       THD_FATAL_ERROR( "Illegal block type in THD_find_atr" ) ;
00325 
00326    if( blk->natr == 0 || blk->atr == NULL ) RETURN(NULL) ;
00327 
00328    /* loop over attributes and check names */
00329 
00330    for( ia=0 ; ia < blk->natr ; ia++ ){
00331       char *aname ;
00332       ATR_any *next_atr = &(blk->atr[ia]) ;  /* pointer to this atr */
00333 
00334       /* extract pointer to name from next_atr */
00335 
00336       switch( next_atr->type ){
00337 
00338          default: aname = NULL ; break ;
00339 
00340          case ATR_FLOAT_TYPE:{
00341             ATR_float *aa = (ATR_float *) next_atr ;
00342             aname = aa->name ;
00343          }
00344          break ;
00345 
00346          case ATR_STRING_TYPE:{
00347             ATR_string *aa = (ATR_string *) next_atr ;
00348             aname = aa->name ;
00349          }
00350          break ;
00351 
00352          case ATR_INT_TYPE:{
00353             ATR_int *aa = (ATR_int *) next_atr ;
00354             aname = aa->name ;
00355          }
00356          break ;
00357       }
00358 
00359       /* check if names match; if so, return the result */
00360 
00361       if( aname != NULL && strcmp(aname,name) == 0 ) RETURN(next_atr) ;
00362 
00363    } /* end of loop over attributes */
00364 
00365    RETURN(NULL) ;  /* none matched */
00366 }

char* THD_find_executable char *    ename
 

Find an executable in the PATH by its name, if it exists. If not, NULL is returned. If it exists, a pointer to static storage is returned (i.e., don't free() this pointer!). ------------------------------------------------------------------------------

Definition at line 13 of file thd_getpathprogs.c.

00014 {
00015    char *etr , *str ;
00016    int ii ;
00017 
00018 ENTRY("THD_find_executable") ;
00019 
00020    if( !einit ){ einit = 1 ; elist = THD_getpathprogs(NULL) ; }
00021    if( elist == NULL ) RETURN(NULL) ;
00022 
00023    etr = THD_trailname( ename , 0 ) ;
00024 
00025    for( ii=0 ; ii < elist->num ; ii++ ){
00026       str = THD_trailname( elist->ar[ii] , 0 ) ;
00027       if( strcmp(str,etr) == 0 ) RETURN(elist->ar[ii]) ;
00028    }
00029 
00030    RETURN(NULL) ;
00031 }

ATR_float* THD_find_float_atr THD_datablock  ,
char *   
 

Definition at line 370 of file thd_atr.c.

References ATR_FLOAT_TYPE, name, THD_find_atr(), and ATR_any::type.

Referenced by main(), SUMA_VolParFromDset(), THD_3dim_from_block(), THD_datablock_from_atr(), THD_read_dvecmat(), and VL_command_line().

00371 {
00372    ATR_any *aa ;
00373    aa = THD_find_atr( blk , name ) ;
00374 
00375    if( aa == NULL || aa->type != ATR_FLOAT_TYPE ) return NULL ;
00376    else                                           return (ATR_float *) aa ;
00377 }

ATR_int* THD_find_int_atr THD_datablock  ,
char *   
 

Definition at line 381 of file thd_atr.c.

References ATR_INT_TYPE, name, THD_find_atr(), and ATR_any::type.

Referenced by Display_Notes(), T3D_geometry_parent_CB(), THD_3dim_from_block(), THD_datablock_from_atr(), THD_dataset_info(), tross_Add_Note(), tross_Delete_Note(), tross_Get_Note(), tross_Get_Notecount(), tross_Get_Notedate(), and tross_Store_Note().

00382 {
00383    ATR_any *aa ;
00384    aa = THD_find_atr( blk , name ) ;
00385 
00386    if( aa == NULL || aa->type != ATR_INT_TYPE ) return NULL ;
00387    else                                         return (ATR_int *) aa ;
00388 }

ATR_string* THD_find_string_atr THD_datablock  ,
char *   
 

Definition at line 392 of file thd_atr.c.

References ATR_STRING_TYPE, name, THD_find_atr(), and ATR_any::type.

Referenced by DRAW_copy_dset(), DRAW_finalize_dset_CB(), main(), THD_3dim_from_block(), THD_datablock_from_atr(), THD_dataset_info(), THD_load_datablock(), tross_Append_History(), tross_Delete_Note(), tross_Get_History(), tross_Get_Note(), and tross_Get_Notedate().

00393 {
00394    ATR_any *aa ;
00395    aa = THD_find_atr( blk , name ) ;
00396 
00397    if( aa == NULL || aa->type != ATR_STRING_TYPE ) return NULL ;
00398    else                                            return (ATR_string *)aa;
00399 }

int thd_floatscan int   ,
float *   
 

Definition at line 25 of file thd_floatscan.c.

References IS_GOOD_FLOAT.

Referenced by AFNI_fimmer_compute(), drive_MCW_grapher(), main(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), mri_read3D_analyze75(), mri_read_analyze75(), T3D_read_images(), THD_load_analyze(), THD_load_datablock(), THD_load_nifti(), THD_open_analyze(), and THD_warp3D().

00026 {
00027    int ii , nerr ;
00028 
00029    if( nbuf <= 0 || fbuf == NULL ) return 0 ;
00030 
00031    for( nerr=ii=0 ; ii < nbuf ; ii++ ){
00032       if( !IS_GOOD_FLOAT(fbuf[ii]) ){ fbuf[ii] = 0.0 ; nerr++ ; }
00033    }
00034 
00035    return nerr ;
00036 }

void THD_force_malloc_type THD_datablock  ,
int   
 

Definition at line 13 of file thd_forcemalloc.c.

References AFNI_yesenv(), THD_diskptr::brick_name, THD_diskptr::byte_order, COMPRESS_filecode(), DATABLOCK_MEM_ANY, DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DBLK_LOCKED, DBLK_mmapfix, THD_datablock::diskptr, ISVALID_DATABLOCK, THD_datablock::malloc_type, MMAP_THRESHOLD, mri_short_order(), native_order, no_mmap, THD_purge_datablock(), and THD_datablock::total_bytes.

Referenced by B2F_read_opts(), BUCK_read_opts(), EDIT_dset_items(), EDIT_one_dataset(), main(), PLUTO_add_dset(), RT_tell_afni_one(), TCAT_read_opts(), and ZCAT_read_opts().

00014 {
00015    int new_type ;
00016 
00017    no_mmap = AFNI_yesenv("AFNI_NOMMAP") ;
00018 
00019    if( native_order < 0 ) native_order = mri_short_order() ;
00020 
00021    /*-- sanity checks --*/
00022 
00023    if( ! ISVALID_DATABLOCK(blk) ) return ;
00024 
00025    if( mem_type == DATABLOCK_MEM_ANY ){  /* 14 Oct 1996 */
00026 #if MMAP_THRESHOLD > 0
00027       new_type = (blk->total_bytes > MMAP_THRESHOLD)
00028                     ? DATABLOCK_MEM_MMAP : DATABLOCK_MEM_MALLOC ;
00029 #else
00030       new_type = DATABLOCK_MEM_MALLOC ;
00031 #endif
00032 
00033    } else {
00034       new_type = mem_type ;
00035    }
00036 
00037    if( COMPRESS_filecode(blk->diskptr->brick_name) >= 0 && new_type == DATABLOCK_MEM_MMAP )
00038       new_type = DATABLOCK_MEM_MALLOC ;
00039 
00040    /* 25 April 1998: byte order issues */
00041 
00042    if( blk->diskptr->byte_order <= 0 )
00043       blk->diskptr->byte_order = native_order ;
00044    else if( blk->diskptr->byte_order != native_order && new_type == DATABLOCK_MEM_MMAP )
00045       new_type = DATABLOCK_MEM_MALLOC ;
00046 
00047    if( no_mmap && new_type == DATABLOCK_MEM_MMAP )
00048       new_type = DATABLOCK_MEM_MALLOC ;
00049 
00050    if( DBLK_LOCKED(blk) )                /* 22 Mar 2001 */
00051       new_type = DATABLOCK_MEM_MALLOC ;
00052 
00053    if( blk->malloc_type == new_type ) return ;
00054    (void) THD_purge_datablock( blk , blk->malloc_type ) ;
00055    blk->malloc_type = new_type ;
00056 
00057    DBLK_mmapfix(blk) ;  /* 28 Mar 2005 */
00058    return ;
00059 }

int THD_freemegabytes char *    pathname
 

Get free space (in megabytes) on a disk partition. Return value is -1 if can't be determined. ----------------------------------------------------------------

Definition at line 288 of file thd_filestuff.c.

References FNAME, and FSTYP.

Referenced by AFNI_startup_timeout_CB().

00289 {
00290 #ifdef FNAME
00291    int ii ; struct FSTYP buf ;
00292    if( pathname == NULL || *pathname == '\0' ) return -1 ;
00293    ii = FNAME( pathname , &buf ) ;
00294    if( ii ) return -1 ;
00295    ii = (int)((double)(buf.BFREE) * (double)(buf.BSIZE) / (1024.0*1024.0)) ;
00296    return ii ;
00297 #else
00298    return -1 ;
00299 #endif
00300 }

void THD_generic_detrend int    npt,
float *    far,
int    polort,
int    nort,
float **    ort
 

Detrend a vector with a given polort level, plus some others. -------------------------------------------------------------------------

Definition at line 200 of file thd_detrend.c.

References far, fit, free, lsqfit(), malloc, and ref.

Referenced by main().

00202 {
00203    int ii,jj , nref ;
00204    float **ref , *fit , xmid , xfac , val ;
00205 
00206    /* check inputs */
00207 
00208    if( npt <= 1 || far == NULL ) return ;
00209    if( nort > 0 ){
00210      if( ort == NULL ) return ;
00211      for( jj=0 ; jj < nort ; jj++ ) if( ort[jj] == NULL ) return ;
00212    }
00213    if( polort <  0 ) polort = -1 ;
00214    if( nort   <  0 ) nort   =  0 ;
00215 
00216    nref = polort+1+nort ;
00217    if( nref == 0 || nref >= npt-1 ) return ;
00218 
00219    ref  = (float **) malloc( sizeof(float *) * nref ) ;
00220    xmid = 0.5*(npt-1) ; xfac = 1.0 / xmid ;
00221    for( jj=0 ; jj <= polort ; jj++ ){
00222      ref[jj] = (float *) malloc( sizeof(float) * npt ) ;
00223      switch( jj ){
00224        case 0:
00225          for( ii=0 ; ii < npt ; ii++ ) ref[jj][ii] = 1.0 ;
00226        break ;
00227 
00228        case 1:
00229          for( ii=0 ; ii < npt ; ii++ ) ref[jj][ii] = xfac*(ii-xmid) ;
00230        break ;
00231 
00232        case 2:
00233          for( ii=0 ; ii < npt ; ii++ ){
00234            val = xfac*(ii-xmid) ; ref[jj][ii] = val*val ;
00235          }
00236        break ;
00237 
00238        case 3:
00239          for( ii=0 ; ii < npt ; ii++ ){
00240            val = xfac*(ii-xmid) ; ref[jj][ii] = val*val*val ;
00241          }
00242        break ;
00243 
00244        default:
00245          for( ii=0 ; ii < npt ; ii++ ){
00246            val = xfac*(ii-xmid) ; ref[jj][ii] = pow(val,(double)(jj)) ;
00247          }
00248        break ;
00249      }
00250    }
00251    for( jj=0 ; jj < nort ; jj++ )   /* user supplied refs */
00252      ref[polort+1+jj] = ort[jj] ;
00253 
00254    fit = lsqfit( npt , far , NULL , nref , ref ) ;
00255 
00256    if( fit != NULL ){                                   /* good */
00257      for( ii=0 ; ii < npt ; ii++ ){
00258        val = far[ii] ;
00259        for( jj=0 ; jj < nref ; jj++ )
00260          val -= fit[jj] * ref[jj][ii] ;
00261        far[ii] = val ;
00262      }
00263      free(fit) ;
00264    } else {
00265      fprintf(stderr,"THD_generic_detrend: lsqfit fails - no detrending!\n") ;
00266    }
00267 
00268    for( jj=0 ; jj <= polort ; jj++ ) free(ref[jj]) ;
00269    free(ref) ; return ;
00270 }

THD_string_array* THD_get_all_executables char *    dname
 

Read all executable filenames from a directory.

Definition at line 128 of file thd_getpathprogs.c.

References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, ENTRY, far, INIT_SARR, THD_string_array::num, RETURN, SARR_NUM, STATUS, THD_extract_regular_files(), THD_get_all_filenames(), and THD_is_executable().

Referenced by THD_getpathprogs().

00129 {
00130    int ir , ll , ii ;
00131    char *fname , *tname ;
00132    float *far ;
00133    THD_string_array *outar, *alist, *rlist ;
00134 
00135 ENTRY("THD_get_all_executables") ;
00136 
00137    /*----- sanity check and initialize -----*/
00138 
00139    if( dname == NULL || strlen(dname) == 0 ) RETURN(NULL) ;
00140    INIT_SARR( outar ) ;
00141 
00142    /*----- find all regular files -----*/
00143 
00144 if(PRINT_TRACING){
00145 char str[256];sprintf(str,"call THD_get_all_filenames(%s)",dname); STATUS(str);
00146 }
00147    alist = THD_get_all_filenames( dname ) ;
00148 
00149    if( alist == NULL ) RETURN(NULL) ;
00150 STATUS("call THD_extract_regular_files") ;
00151    rlist = THD_extract_regular_files( alist ) ;
00152    DESTROY_SARR( alist ) ;
00153    if( rlist == NULL ) RETURN(NULL) ;
00154 
00155    /* 04 Feb 2002: don't include .so libraries, etc. */
00156 
00157    for( ir=0 ; ir < rlist->num ; ir++ ){
00158       fname = rlist->ar[ir] ;
00159       if( THD_is_executable(fname) &&
00160           !strstr(fname,".so")     &&
00161           !strstr(fname,".la")       ) ADDTO_SARR(outar,fname) ;
00162    }
00163 
00164    DESTROY_SARR(rlist) ;
00165 
00166    if( SARR_NUM(outar) == 0 ) DESTROY_SARR(outar) ;
00167 
00168    RETURN( outar );
00169 }

THD_string_array* THD_get_all_filenames char *   
 

Definition at line 75 of file thd_sarr.c.

References ADDTO_SARR, AFREALL, ENTRY, free, INIT_SARR, MCW_file_expand(), MCW_free_expand(), MCW_warn_expand(), myXtFree, RETURN, STATUS, THD_is_directory(), and XtMalloc.

Referenced by NLFIT_get_all_MODELs(), PLUG_get_all_plugins(), THD_get_all_executables(), THD_get_all_subdirs(), THD_get_all_timeseries(), and THD_init_alldir_datablocks().

00076 {
00077 #ifndef DONT_USE_SCANDIR
00078    struct dirent ** dplist=NULL ;
00079 #endif
00080    int nfiles , dlen , ii , n_fname , max_fname ;
00081    THD_string_array * star ;
00082    char * total_dirname , * total_fname ;
00083    char ** gname=NULL ;
00084 
00085 ENTRY("THD_get_all_filenames") ;
00086 
00087    if( dirname == NULL || (dlen=strlen(dirname)) == 0 ) RETURN( NULL );
00088    if( ! THD_is_directory(dirname) )                    RETURN( NULL );
00089 
00090    total_dirname = (char*)XtMalloc( dlen+4 ) ;
00091    strcpy( total_dirname , dirname ) ;
00092    if( total_dirname[dlen-1] != '/' ){
00093       total_dirname[dlen]   = '/' ;     /* add a slash */
00094       total_dirname[++dlen] = '\0' ;
00095    }
00096 
00097 #ifdef DONT_USE_SCANDIR
00098    total_dirname[dlen]   = '*' ;                            /* add wildcard */
00099    total_dirname[++dlen] = '\0' ;
00100    MCW_warn_expand(0) ;
00101 if(PRINT_TRACING){
00102  char str[256]; sprintf(str,"MCW_file_expand(%s)",total_dirname); STATUS(str);
00103 }
00104    MCW_file_expand( 1, &total_dirname, &nfiles, &gname ) ;  /* find files */
00105 #else
00106    nfiles = scandir( dirname ,
00107                      &dplist ,
00108                      THD_select_dirent ,
00109                      alphasort ) ;
00110 #endif
00111 
00112    if( nfiles < 1 ){
00113        myXtFree( total_dirname ) ;
00114 #ifdef DONT_USE_SCANDIR
00115        if( gname != NULL ) free(gname) ;
00116 #else
00117        if( dplist != NULL ) free(dplist) ;
00118 #endif
00119        RETURN( NULL );
00120    }
00121 
00122    INIT_SARR( star ) ;
00123 
00124 #ifndef DONT_USE_SCANDIR
00125    max_fname   = dlen+64 ;
00126    total_fname = (char*)XtMalloc( max_fname ) ;
00127 #endif
00128 
00129    for( ii=0 ; ii < nfiles ; ii++ ){
00130 #ifdef DONT_USE_SCANDIR
00131       ADDTO_SARR( star , gname[ii] ) ;
00132 #else
00133       n_fname = dlen + strlen( dplist[ii]->d_name ) + 4 ;
00134       if( n_fname > max_fname ){
00135          total_fname = AFREALL(total_fname, char, n_fname ) ;
00136          max_fname   = n_fname ;
00137       }
00138       strcpy( total_fname , total_dirname ) ;
00139       strcat( total_fname , dplist[ii]->d_name ) ;
00140       ADDTO_SARR( star , total_fname ) ;
00141       free( dplist[ii] ) ;
00142 #endif
00143    }
00144 
00145    myXtFree( total_dirname ) ;
00146 #ifdef DONT_USE_SCANDIR
00147    MCW_free_expand( nfiles , gname ) ;
00148 #else
00149    myXtFree( total_fname ) ;
00150    free( dplist ) ;
00151 #endif
00152    RETURN( star );
00153 }

THD_string_array* THD_get_all_subdirs int   ,
char *   
 

Definition at line 160 of file thd_sarr.c.

References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, INIT_SARR, myXtFree, THD_string_array::num, THD_extract_directories(), THD_get_all_filenames(), and XtMalloc.

Referenced by AFNI_read_inputs().

00161 {
00162    int ii , jj , dlen ;
00163    THD_string_array * star , * flist , * dlist ;
00164    char * total_dirname ;
00165 
00166    if( dirname == NULL || (dlen=strlen(dirname)) == 0 ) return NULL ;
00167 
00168    total_dirname = (char*)XtMalloc( dlen+2 ) ;
00169    strcpy( total_dirname , dirname ) ;
00170    if( total_dirname[dlen-1] != '/' ){
00171       total_dirname[dlen]   = '/' ;
00172       total_dirname[++dlen] = '\0' ;
00173    }
00174 
00175    INIT_SARR( star ) ;
00176    ADDTO_SARR( star , total_dirname ) ;
00177 
00178    /** want only this level? **/
00179 
00180    if( lev <= 0 ) return star ;
00181 
00182    /** must want deeper levels **/
00183 
00184    flist = THD_get_all_filenames( total_dirname ) ;
00185    myXtFree(total_dirname) ;
00186 
00187    if( flist == NULL ) return star ;
00188    if( flist->num == 0 ){ DESTROY_SARR(flist) ; return star ; }
00189 
00190    dlist = THD_extract_directories( flist ) ;
00191    DESTROY_SARR(flist) ;
00192    if( dlist == NULL ) return star ;
00193    if( dlist->num == 0 ){ DESTROY_SARR(dlist) ; return star ; }
00194 
00195    for( ii=0 ; ii < dlist->num ; ii++ ){
00196       flist = THD_get_all_subdirs( lev-1 , dlist->ar[ii] ) ;
00197       if( flist == NULL ) continue ;
00198       for( jj=0 ; jj < flist->num ; jj++ ){
00199          ADDTO_SARR( star , flist->ar[jj] ) ;
00200       }
00201       DESTROY_SARR(flist) ;
00202    }
00203 
00204    DESTROY_SARR(dlist) ;
00205    return star ;
00206 }

MRI_IMARR* THD_get_all_timeseries char *   
 

Definition at line 120 of file thd_get1D.c.

References ADDTO_IMARR, AFNI_numenv(), THD_string_array::ar, DESTROY_IMARR, DESTROY_SARR, far, free, IMARR_COUNT, INIT_IMARR, malloc, mri_add_name(), MRI_FLOAT_PTR, mri_read_1D(), THD_string_array::num, MRI_IMAGE::nvox, pat, THD_extract_regular_files(), THD_filesize(), THD_get_all_filenames(), THD_get_wildcard_filenames(), and THD_trailname().

Referenced by THD_get_many_timeseries().

00121 {
00122    THD_string_array * flist , * rlist ;
00123    int ir , ll , ii ;
00124    char * fname , * tname ;
00125    float * far ;
00126    MRI_IMARR * outar ;
00127    MRI_IMAGE * outim , * flim ;
00128 
00129 #ifdef NEWWAY
00130    char * pat ;
00131 #endif
00132 
00133    unsigned long max_fsize ;  /* 20 Jul 2004: max 1D file size to load */
00134 
00135    max_fsize = (unsigned long) AFNI_numenv( "AFNI_MAX_1DSIZE" ) ;
00136    if( max_fsize == 0 ) max_fsize = 123*1024 ;
00137 
00138    /*----- sanity check and initialize -----*/
00139 
00140    if( dname == NULL || strlen(dname) == 0 ) return NULL ;
00141    INIT_IMARR( outar ) ;
00142 
00143    /*----- find all *.1D files -----*/
00144 
00145 #ifdef NEWWAY
00146    ii  = strlen(dname) ;
00147    pat = (char *) malloc(sizeof(char)*(ii+8)) ;
00148    strcpy(pat,dname) ;
00149    if( pat[ii-1] != '/' ) strcat(pat,"/") ;
00150    strcat(pat,"*.1D*") ;
00151    flist = THD_get_wildcard_filenames( pat ) ;
00152    free(pat) ;
00153 #else
00154    flist = THD_get_all_filenames( dname ) ;
00155 #endif
00156 
00157    if( flist == NULL || flist->num <= 0 ){
00158       DESTROY_SARR(flist) ;
00159       DESTROY_IMARR(outar) ;
00160       return NULL ;
00161    }
00162 
00163    rlist = THD_extract_regular_files( flist ) ;
00164    DESTROY_SARR(flist) ;
00165    if( rlist == NULL || rlist->num <= 0 ){
00166       DESTROY_SARR(rlist) ;
00167       DESTROY_IMARR(outar) ;
00168       return NULL ;
00169    }
00170 
00171    for( ir=0 ; ir < rlist->num ; ir++ ){
00172       fname = rlist->ar[ir] ; if( fname == NULL ) continue ;
00173 
00174       ll = strlen(fname) - 3 ; if( ll < 1 ) continue ;
00175 
00176       if( strcmp(fname+ll,".1D")==0 ||
00177           strcmp(fname+ll,"1Dx")==0 ||
00178           strcmp(fname+ll,"1Dv")==0   ){
00179 
00180          if( THD_filesize(fname) > max_fsize ) continue ;  /* 20 Jul 2004 */
00181 
00182          flim = mri_read_1D( fname ) ;
00183          if( flim != NULL ){
00184             far = MRI_FLOAT_PTR(flim) ;
00185             for( ii=0 ; ii < flim->nvox ; ii++ )
00186                if( fabs(far[ii]) >= 33333.0 ) far[ii] = WAY_BIG ;
00187 
00188             tname = THD_trailname(fname,1) ;
00189             mri_add_name( tname , flim ) ;
00190             ADDTO_IMARR( outar , flim ) ;
00191          }
00192       }
00193    }
00194 
00195    DESTROY_SARR(rlist) ;
00196 
00197    if( IMARR_COUNT(outar) == 0 ) DESTROY_IMARR(outar) ;
00198 
00199    return outar ;
00200 }

int THD_get_axis_direction THD_dataxes   daxes,
int    orient_code
 

Input is a dataset axes struct and an orientation code. Output is an int saying which dataset axis is this code.

  • +1 => dataset +x-axis
  • -1 => dataset -x-axis, etc.
  • 0 => bad inputs
  • RWCox - 19 Mar 2003 -----------------------------------------------------------------------------

Definition at line 12 of file thd_getorient.c.

References ORIENT_OPPOSITE, THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by main().

00013 {
00014    if( daxes == NULL ) return 0;
00015 
00016    if(                 daxes->xxorient  == orient_code ) return  1 ;
00017    if( ORIENT_OPPOSITE(daxes->xxorient) == orient_code ) return -1 ;
00018    if(                 daxes->yyorient  == orient_code ) return  2 ;
00019    if( ORIENT_OPPOSITE(daxes->yyorient) == orient_code ) return -2 ;
00020    if(                 daxes->zzorient  == orient_code ) return  3 ;
00021    if( ORIENT_OPPOSITE(daxes->zzorient) == orient_code ) return -3 ;
00022    return 0 ;
00023 }

void* THD_get_dset_row THD_3dim_dataset   dset,
int    ival,
int    dcode,
int    xx,
int    yy,
int    zz
 

Extract a row from a dataset sub-brick in the direction given by dcode. The 3-index of a voxel from the row is in (xx,yy,zz). The return value is a pointer to a malloc()-ed array, whose type is given by DSET_BRICK_TYPE(dset,ival) and whose length is given by THD_get_dset_rowcount(dset,dcode). If NULL is returned, something bad happened. N.B.: dcode < 0 ==> data is extracted in the reverse direction. -----------------------------------------------------------------------------

Definition at line 41 of file thd_dsetrow.c.

References AFMALL, DSET_ARRAY, DSET_BRICK_TYPE, DSET_NX, DSET_NY, DSET_NZ, ENTRY, free, mri_datum_size(), nz, RETURN, and THD_get_dset_rowcount().

Referenced by main(), THD_dataset_rowfillin(), and THD_dataset_zfillin().

00043 {
00044    void *row , *brick ;
00045    int nrow , kind , nx,ny,nz,nxy , kbot,kdel,kk,ii ;
00046 
00047 ENTRY("THD_get_dset_row") ;
00048 
00049    nrow = THD_get_dset_rowcount( dset , dcode ) ;
00050    if( nrow < 1 ) RETURN(NULL) ;
00051 
00052    nx = DSET_NX(dset) ;
00053    ny = DSET_NY(dset) ; nxy = nx*ny ;
00054    nz = DSET_NZ(dset) ;
00055 
00056    /*-- We will extract brick[kbot+i*kdel] for i=0..nrow-1 --*/
00057 
00058    switch( dcode ){
00059       case 1: case -1:
00060          if( yy < 0 || yy >= ny || zz < 0 || zz >= nz ) RETURN(NULL) ;
00061          kbot = yy*nx + zz*nxy ; kdel = 1 ;
00062       break ;
00063 
00064       case 2: case -2:
00065          if( xx < 0 || xx >= nx || zz < 0 || zz >= nz ) RETURN(NULL) ;
00066          kbot = xx + zz*nxy ; kdel = nx ;
00067       break ;
00068 
00069       case 3: case -3:
00070          if( xx < 0 || xx >= nx || yy < 0 || yy >= ny ) RETURN(NULL) ;
00071          kbot = xx + yy*nx ; kdel = nxy ;
00072       break ;
00073    }
00074 
00075    kind  = DSET_BRICK_TYPE(dset,ival) ;
00076    brick = DSET_ARRAY(dset,ival) ;
00077    row   = AFMALL(void, mri_datum_size((MRI_TYPE)kind) * nrow ) ;
00078 
00079    /*-- extract row, based on kind of data in sub-brick --*/
00080 
00081    switch( kind ){
00082 
00083       default: free(row) ; RETURN(NULL) ;  /* bad */
00084 
00085       case MRI_short:{
00086          short *rr = (short *)row , *bb = (short *)brick ;
00087          if( dcode > 0 )
00088             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[ii] = bb[kk+kbot] ;
00089          else
00090             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[nrow-1-ii] = bb[kk+kbot] ;
00091       }
00092       break ;
00093 
00094       case MRI_byte:{
00095          byte *rr = (byte *)row , *bb = (byte *)brick ;
00096          if( dcode > 0 )
00097             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[ii] = bb[kk+kbot] ;
00098          else
00099             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[nrow-1-ii] = bb[kk+kbot] ;
00100       }
00101       break ;
00102 
00103       case MRI_float:{
00104          float *rr = (float *)row , *bb = (float *)brick ;
00105          if( dcode > 0 )
00106             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[ii] = bb[kk+kbot] ;
00107          else
00108             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[nrow-1-ii] = bb[kk+kbot] ;
00109       }
00110       break ;
00111 
00112       case MRI_complex:{
00113          complex *rr = (complex *)row , *bb = (complex *)brick ;
00114          if( dcode > 0 )
00115             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[ii] = bb[kk+kbot] ;
00116          else
00117             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) rr[nrow-1-ii] = bb[kk+kbot] ;
00118       }
00119       break ;
00120 
00121       case MRI_rgb:{
00122          byte *rr = (byte *)row , *bb = (byte *)brick ;
00123          if( dcode > 0 )
00124             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ){
00125                rr[3*ii  ] = bb[3*(kk+kbot)  ] ;
00126                rr[3*ii+1] = bb[3*(kk+kbot)+1] ;
00127                rr[3*ii+2] = bb[3*(kk+kbot)+2] ;
00128             }
00129          else
00130             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ){
00131                rr[3*(nrow-1-ii)  ] = bb[3*(kk+kbot)  ] ;
00132                rr[3*(nrow-1-ii)+1] = bb[3*(kk+kbot)+1] ;
00133                rr[3*(nrow-1-ii)+2] = bb[3*(kk+kbot)+2] ;
00134             }
00135       }
00136       break ;
00137    }
00138 
00139    RETURN(row) ;
00140 }

int THD_get_dset_rowcount THD_3dim_dataset   dset,
int    dcode
 

Get the number of elements in a row of the dataset in a particular direction given by dcode:

  • +1 = x direction -1 = reversed x direction
  • +2 = y direction -2 = reversed y direction
  • +3 = z direction -3 = reversed z direction
This routine is mostly for the pitiful programmer who can't be bothered to do this calculation himself. -----------------------------------------------------------------------------

Definition at line 20 of file thd_dsetrow.c.

References DSET_NX, DSET_NY, DSET_NZ, and ISVALID_DSET.

Referenced by THD_dataset_rowfillin(), THD_dataset_zfillin(), THD_get_dset_row(), and THD_put_dset_row().

00021 {
00022    if( !ISVALID_DSET(dset) ) return 0 ;        /* bad */
00023    switch( dcode ){
00024       case  1: case -1: return DSET_NX(dset) ; /* good */
00025       case  2: case -2: return DSET_NY(dset) ; /* good */
00026       case  3: case -3: return DSET_NZ(dset) ; /* good */
00027    }
00028    return 0 ;                                  /* bad */
00029 }

MRI_IMARR* THD_get_many_timeseries THD_string_array  
 

Definition at line 14 of file thd_get1D.c.

References ADDTO_IMARR, ADDTO_SARR, THD_string_array::ar, DESTROY_IMARR, DESTROY_SARR, ENTRY, EXIT, free, FREE_IMARR, MRI_IMARR::imarr, IMARR_COUNT, INIT_IMARR, INIT_SARR, malloc, my_getenv(), THD_string_array::num, MRI_IMARR::num, RETURN, THD_equiv_files(), THD_get_all_timeseries(), THD_is_directory(), and THD_MAX_NAME.

Referenced by AFNI_read_inputs(), and AFNI_rescan_timeseries_CB().

00015 {
00016    int id , ii , ndir ;
00017    MRI_IMARR * outar , * tmpar ;
00018    char * epath , * eee ;
00019    char   efake[] = "./" ;
00020    THD_string_array *qlist ; /* 02 Feb 2002 */
00021 
00022 ENTRY("THD_get_many_timeseries") ;
00023 
00024    /*----- sanity check and initialize -----*/
00025 
00026                        epath = my_getenv( "AFNI_TSPATH" ) ;
00027    if( epath == NULL ) epath = my_getenv( "AFNI_TS_PATH" ) ; /* 07 Oct 1996 */
00028    if( epath == NULL ) epath = efake ;                      /* 07 Oct 1996 */
00029 
00030    ndir = (dlist != NULL) ? dlist->num : 0 ;
00031 
00032    if( ndir == 0 && epath == NULL ) RETURN( NULL ) ;
00033 
00034    INIT_IMARR( outar ) ;
00035    INIT_SARR( qlist ) ;
00036 
00037    /*----- for each input directory, find all *.1D files -----*/
00038 
00039    for( id=0 ; id < ndir ; id++ ){
00040 
00041       ADDTO_SARR(qlist,dlist->ar[id]) ;
00042 
00043       tmpar = THD_get_all_timeseries( dlist->ar[id] ) ;
00044       if( tmpar == NULL ) continue ;
00045 
00046       for( ii=0 ; ii < tmpar->num ; ii++ )  /* move images to output array */
00047          ADDTO_IMARR( outar , tmpar->imarr[ii] ) ;
00048 
00049       FREE_IMARR(tmpar) ;  /* don't need this no more */
00050    }
00051 
00052    /*----- also do directories in environment path, if any -----*/
00053 
00054    if( epath != NULL ){
00055       int epos =0 , ll = strlen(epath) ;
00056       char * elocal ;
00057       char ename[THD_MAX_NAME] ;
00058 
00059       /* copy path list into local memory */
00060 
00061       elocal = (char *) malloc( sizeof(char) * (ll+2) ) ;
00062       if( elocal == NULL ){
00063          fprintf(stderr,
00064                 "\n*** THD_get_many_timeseries malloc failure - is memory full? ***\n");
00065          EXIT(1) ;
00066       }
00067       strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ;
00068 
00069       /* replace colons with blanks */
00070 
00071       for( ii=0 ; ii < ll ; ii++ )
00072          if( elocal[ii] == ':' ) elocal[ii] = ' ' ;
00073 
00074       /* extract blank delimited strings,
00075          use as directory names to get timeseries files */
00076 
00077       do{
00078          ii = sscanf( elocal+epos , "%s%n" , ename , &id ) ;
00079          if( ii < 1 ) break ;  /* no read --> end of work */
00080          epos += id ;          /* epos = char after last one scanned */
00081 
00082          ii = strlen(ename) ;                         /* make sure name has */
00083          if( ename[ii-1] != '/' ){                    /* a trailing '/' on it */
00084             ename[ii]  = '/' ; ename[ii+1] = '\0' ;
00085          }
00086 
00087          if( !THD_is_directory(ename) ) continue ;  /* 21 May 2002 - rcr */
00088 
00089          /* 02 Feb 2002: check if scanned this directory before */
00090 
00091          for( ii=0 ; ii < qlist->num ; ii++ )
00092             if( THD_equiv_files(qlist->ar[ii],ename) ) break ;
00093          if( ii < qlist->num ) continue ;  /* skip to end of do loop */
00094          ADDTO_SARR(qlist,ename) ;
00095 
00096          tmpar = THD_get_all_timeseries( ename ) ; /* read this directory */
00097          if( tmpar != NULL ){
00098             for( ii=0 ; ii < tmpar->num ; ii++ )   /* move images to output array */
00099                ADDTO_IMARR( outar , tmpar->imarr[ii] ) ;
00100 
00101             FREE_IMARR(tmpar) ;                    /* don't need this no more */
00102          }
00103       } while( epos < ll ) ;  /* scan until 'epos' is after end of epath */
00104 
00105       free(elocal) ;
00106    }
00107 
00108    if( IMARR_COUNT(outar) == 0 ) DESTROY_IMARR(outar) ;
00109 
00110    DESTROY_SARR(qlist) ;
00111    RETURN( outar ) ;
00112 }

float THD_get_voxel THD_3dim_dataset   dset,
int    ijk,
int    ival
 

Return a float representation of a given voxel. [15 Sep 2004] -----------------------------------------------------------------

Definition at line 40 of file thd_loaddblk.c.

References rgba::a, rgbyte::b, rgba::b, c, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_NVALS, DSET_NVOX, rgbyte::g, rgba::g, complex::i, complex::r, rgbyte::r, and rgba::r.

Referenced by FD_brick_to_series().

00041 {
00042    void *ar ;
00043    float val , fac ;
00044 
00045    if( ival < 0 || ival >= DSET_NVALS(dset) ) return 0.0f ;
00046    if( ijk < 0  || ijk  >= DSET_NVOX(dset)  ) return 0.0f ;
00047 
00048    ar = DSET_ARRAY(dset,ival) ;
00049    if( ar == NULL ){ DSET_load(dset) ; ar = DSET_ARRAY(dset,ival) ; }
00050    if( ar == NULL ) return 0.0f ;
00051 
00052    switch( DSET_BRICK_TYPE(dset,ival) ){
00053 
00054      default: return 0.0f ;
00055 
00056      case MRI_byte:
00057        val = (float)(((byte *)ar)[ijk])   ; break ;
00058      case MRI_short:
00059        val = (float)(((short *)ar)[ijk])  ; break ;
00060      case MRI_int:
00061        val = (float)(((int *)ar)[ijk])    ; break ;
00062      case MRI_float:
00063        val = (float)(((float *)ar)[ijk])  ; break ;
00064      case MRI_double:
00065        val = (float)(((double *)ar)[ijk]) ; break ;
00066 
00067      case MRI_complex:{
00068        complex c = (((complex *)ar)[ijk]) ;
00069        val = sqrt(c.r*c.r+c.i*c.i) ;
00070        break ;
00071      }
00072 
00073      case MRI_rgb:{
00074        rgbyte c = (((rgbyte *)ar)[ijk]) ;
00075        val = 0.299f*(float)(c.r) + 0.587f*(float)(c.g) + 0.114f*(float)(c.b) ;
00076        break ;
00077      }
00078 
00079      case MRI_rgba:{
00080        rgba c = (((rgba *)ar)[ijk]) ;
00081        val = 0.299f*(float)(c.r) + 0.587f*(float)(c.g) + 0.114f*(float)(c.b) ;
00082        val *= 0.00392157f*(float)(c.a) ;
00083        break ;
00084      }
00085    }
00086 
00087    fac = DSET_BRICK_FACTOR(dset,ival) ;
00088    if( fac > 0.0f ) val *= fac ;
00089    return val ;
00090 }

THD_string_array* THD_get_wildcard_filenames char *   
 

Definition at line 321 of file thd_sarr.c.

References ADDTO_SARR, free, INIT_SARR, MCW_file_expand(), MCW_free_expand(), MCW_warn_expand(), and pat.

Referenced by THD_get_all_timeseries().

00322 {
00323    int nfiles , ii ;
00324    THD_string_array * star ;
00325    char ** gname=NULL ;
00326 
00327    if( pat == NULL || strlen(pat) == 0 ) return NULL ;
00328 
00329    MCW_warn_expand(0) ;
00330    MCW_file_expand( 1, &pat, &nfiles, &gname ) ;  /* find files */
00331 
00332    if( nfiles < 1 ){
00333        if( gname != NULL ) free(gname) ;
00334        return NULL ;
00335    }
00336 
00337    INIT_SARR( star ) ;
00338 
00339    for( ii=0 ; ii < nfiles ; ii++ ){
00340       ADDTO_SARR( star , gname[ii] ) ;
00341    }
00342 
00343    MCW_free_expand( nfiles , gname ) ;
00344    return star ;
00345 }

int THD_get_write_compression void   
 

Definition at line 25 of file thd_writedblk.c.

References compress_mode, COMPRESS_NOFILE, and THD_enviro_write_compression().

Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), main(), PLUGIN_init(), RT_tell_afni_one(), and RT_worker().

00026 {
00027    if( compress_mode == COMPRESS_NOFILE ) THD_enviro_write_compression() ;
00028    return compress_mode ;
00029 }

int THD_get_write_order void   
 

Definition at line 81 of file thd_writedblk.c.

References mri_short_order(), native_order, output_order, and THD_enviro_write_order().

Referenced by adwarp_follower_dataset(), adwarp_refashion_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), AFNI_refashion_dataset(), duplicate_dataset(), EDIT_empty_copy(), EDIT_empty_datablock(), main(), and T3D_read_images().

00082 {
00083    if( native_order < 0 ) native_order = mri_short_order() ;
00084    if( output_order < 0 ) THD_enviro_write_order() ;
00085 
00086    return (output_order > 0) ? output_order
00087                              : native_order ;
00088 }

THD_string_array* THD_getpathprogs THD_string_array   dlist
 

Return a list of all executable files in the PATH and the dlist.

Definition at line 36 of file thd_getpathprogs.c.

References ADDTO_SARR, THD_string_array::ar, DESTROY_SARR, ENTRY, free, INIT_SARR, malloc, my_getenv(), THD_string_array::num, RETURN, SARR_NUM, THD_equiv_files(), THD_get_all_executables(), THD_is_directory(), and THD_MAX_NAME.

Referenced by THD_find_executable().

00037 {
00038    int id , ii , ndir ;
00039    char *epath , *eee ;
00040    THD_string_array *elist , *tlist , *qlist ;
00041 
00042 ENTRY("THD_getpathprogs") ;
00043 
00044    /*----- sanity check and initialize -----*/
00045 
00046    epath = my_getenv( "PATH" ) ;
00047    ndir  = (dlist != NULL) ? dlist->num : 0 ;
00048 
00049    if( ndir == 0 && epath == NULL ) RETURN(NULL) ;
00050 
00051    INIT_SARR(elist) ;
00052    INIT_SARR(qlist) ;  /* 04 Feb 2002: list of searched directories */
00053 
00054    /*----- for each input directory, find all executable files -----*/
00055 
00056    for( id=0 ; id < ndir ; id++ ){
00057 
00058       tlist = THD_get_all_executables( dlist->ar[id] ) ;
00059       if( tlist == NULL ) continue ;
00060 
00061       for( ii=0 ; ii < tlist->num ; ii++ )  /* copy names to output array */
00062          ADDTO_SARR( elist , tlist->ar[ii] ) ;
00063 
00064       ADDTO_SARR(qlist,dlist->ar[id]) ;     /* 04 Feb 2002 */
00065 
00066       DESTROY_SARR(tlist) ;
00067    }
00068 
00069    /*----- also do directories in environment path, if any -----*/
00070 
00071    if( epath != NULL ){
00072       int epos =0 , ll = strlen(epath) ;
00073       char *elocal ;
00074       char ename[THD_MAX_NAME] ;
00075 
00076       /* copy path list into local memory */
00077 
00078       elocal = (char *) malloc( sizeof(char) * (ll+2) ) ;
00079       strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ;
00080 
00081       /* replace colons with blanks */
00082 
00083       for( ii=0 ; ii < ll ; ii++ )
00084          if( elocal[ii] == ':' ) elocal[ii] = ' ' ;
00085 
00086       /* extract blank delimited strings,
00087          use as directory names to get timeseries files */
00088 
00089       do{
00090          ii = sscanf( elocal+epos , "%s%n" , ename , &id ) ;
00091          if( ii < 1 ) break ;  /* no read ==> end of work */
00092          epos += id ;          /* epos = char after last one scanned */
00093 
00094          ii = strlen(ename) ;                         /* make sure name has */
00095          if( ename[ii-1] != '/' ){                    /* a trailing '/' on it */
00096             ename[ii]  = '/' ; ename[ii+1] = '\0' ;
00097          }
00098          if( !THD_is_directory(ename) ) continue ;    /* 25 Feb 2002 */
00099 
00100          /* 04 Feb 2002: check if we already searched this directory */
00101 
00102          for( ii=0 ; ii < qlist->num ; ii++ )
00103             if( THD_equiv_files(qlist->ar[ii],ename) ) break ;
00104          if( ii < qlist->num ) continue ;  /* skip this directory */
00105          ADDTO_SARR(qlist,ename) ;
00106 
00107          tlist = THD_get_all_executables( ename ) ; /* read this directory */
00108          if( tlist != NULL ){
00109             for( ii=0 ; ii < tlist->num ; ii++ )    /* move names to output */
00110                ADDTO_SARR( elist , tlist->ar[ii] ) ;
00111             DESTROY_SARR(tlist) ;
00112          }
00113 
00114       } while( epos < ll ) ;  /* scan until 'epos' is after end of epath */
00115 
00116       free(elocal) ;
00117    }
00118 
00119    if( SARR_NUM(elist) == 0 ) DESTROY_SARR(elist) ;
00120 
00121    DESTROY_SARR(qlist) ;  /* 04 Feb 2002 */
00122    RETURN(elist) ;
00123 }

int THD_handedness THD_3dim_dataset  
 

Definition at line 124 of file thd_rotangles.c.

References THD_3dim_dataset::daxes, ENTRY, ISVALID_DSET, LOAD_ZERO_MAT, THD_mat33::mat, MAT_DET, q, RETURN, THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by main(), NUD_finalize_dset_CB(), RT_registration_3D_setup(), THD_rotangle_user_to_dset(), and VOLREG_main().

00125 {
00126    THD_dataxes *dax ;
00127    THD_mat33 q ;
00128    int col ;
00129    float val ;
00130 
00131 ENTRY("THD_handedness") ;
00132 
00133    if( !ISVALID_DSET(dset) ) RETURN(1) ;
00134 
00135    LOAD_ZERO_MAT(q) ;
00136    dax = dset->daxes ;
00137 
00138    col = 0 ;
00139    switch( dax->xxorient ){
00140       case 0: q.mat[0][col] =  1.0 ; break ;
00141       case 1: q.mat[0][col] = -1.0 ; break ;
00142       case 2: q.mat[1][col] = -1.0 ; break ;
00143       case 3: q.mat[1][col] =  1.0 ; break ;
00144       case 4: q.mat[2][col] =  1.0 ; break ;
00145       case 5: q.mat[2][col] = -1.0 ; break ;
00146    }
00147 
00148    col = 1 ;
00149    switch( dax->yyorient ){
00150       case 0: q.mat[0][col] =  1.0 ; break ;
00151       case 1: q.mat[0][col] = -1.0 ; break ;
00152       case 2: q.mat[1][col] = -1.0 ; break ;
00153       case 3: q.mat[1][col] =  1.0 ; break ;
00154       case 4: q.mat[2][col] =  1.0 ; break ;
00155       case 5: q.mat[2][col] = -1.0 ; break ;
00156    }
00157 
00158    col = 2 ;
00159    switch( dax->zzorient ){
00160       case 0: q.mat[0][col] =  1.0 ; break ;
00161       case 1: q.mat[0][col] = -1.0 ; break ;
00162       case 2: q.mat[1][col] = -1.0 ; break ;
00163       case 3: q.mat[1][col] =  1.0 ; break ;
00164       case 4: q.mat[2][col] =  1.0 ; break ;
00165       case 5: q.mat[2][col] = -1.0 ; break ;
00166    }
00167 
00168    val = MAT_DET(q) ;
00169    if( val > 0.0 ) RETURN( 1) ;  /* right handed */
00170    else            RETURN(-1) ;  /* left handed */
00171 }

XtPointer_array* THD_init_alldir_datablocks char *   
 

Definition at line 15 of file thd_initalldir.c.

References ADDTO_XTARR, THD_string_array::ar, DATASET_HEADER_SUFFIX, DESTROY_SARR, FILENAME_TO_PREFIX, FREE_DBARR, INIT_XTARR, THD_string_array::num, THD_datablock_array::num, THD_extract_regular_files(), THD_get_all_filenames(), THD_init_prefix_datablocks(), and THD_MAX_NAME.

Referenced by THD_init_session().

00016 {
00017    XtPointer_array     * super_array ;
00018    THD_datablock_array * dblk_arr ;
00019    THD_string_array    * flist , * rlist ;
00020    char prefix[THD_MAX_NAME] ;
00021    char * fname ;
00022    int ifile ;
00023 
00024    /* initialize answer */
00025 
00026    INIT_XTARR( super_array ) ;
00027 
00028    /* get list of all regular files in the directory */
00029 
00030    flist = THD_get_all_filenames( dirname ) ;
00031    if( flist == NULL || flist->num <= 0 ){
00032       DESTROY_SARR(flist) ;
00033       return super_array ;
00034    }
00035 
00036    rlist = THD_extract_regular_files( flist ) ;
00037    DESTROY_SARR(flist) ;
00038    if( rlist == NULL || rlist->num <= 0 ){
00039       DESTROY_SARR(rlist) ;
00040       return super_array ;
00041    }
00042 
00043    /* for each header/prefix combination
00044       in the list, try to get all datablocks within */
00045 
00046    for( ifile=0 ; ifile < rlist->num ; ifile++ ){
00047 
00048       fname = rlist->ar[ifile] ;
00049       if( fname == NULL ||
00050           strstr(fname,DATASET_HEADER_SUFFIX) == NULL ) continue ;
00051 
00052       FILENAME_TO_PREFIX(fname,prefix) ;
00053       if( strlen(prefix) == 0 ) continue ;
00054 
00055       dblk_arr = THD_init_prefix_datablocks( prefix , rlist ) ;
00056 
00057       if( dblk_arr != NULL && dblk_arr->num > 0 ){
00058          ADDTO_XTARR(super_array,dblk_arr) ;       /* store in output */
00059       } else {
00060          FREE_DBARR(dblk_arr) ;                    /* throw it away */
00061       }
00062 
00063    }
00064 
00065    /* done! */
00066 
00067    DESTROY_SARR(rlist) ;
00068    return super_array ;
00069 }

void THD_init_datablock_brick THD_datablock  ,
int   ,
void *   
 

Definition at line 796 of file thd_initdblk.c.

References ADDTO_IMARR, THD_datablock::brick, THD_datablock::brick_bytes, THD_datablock::brick_fac, DBLK_BRICK_TYPE, DESTROY_IMARR, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, INIT_IMARR, ISVALID_DATABLOCK, mri_new_vol_empty(), THD_datablock::nvals, MRI_IMAGE::nvox, nz, MRI_IMAGE::pixel_size, STATUS, THD_datablock::total_bytes, typ, and XtMalloc.

Referenced by adwarp_follower_dataset(), adwarp_refashion_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), AFNI_refashion_dataset(), EDIT_dset_items(), EDIT_empty_copy(), T3D_fix_dataset_dimen(), T3D_read_images(), THD_datablock_from_atr(), and THD_setup_mastery().

00797 {
00798    int ibr , nx,ny,nz , typ , nvals ;
00799    MRI_IMAGE *qim ;
00800    THD_datablock *pblk = NULL ;
00801    int *itype = NULL ;
00802 
00803 ENTRY("THD_init_datablock_brick") ;
00804 
00805    if( ! ISVALID_DATABLOCK(dblk)   ) EXRETURN ;   /* bad inputs */
00806    if( ntype <  0 && btype == NULL ) EXRETURN ;
00807    if( ntype == 0 && btype != NULL ) EXRETURN ;
00808 
00809    if( ntype < 0 ){                            /* copy types from */
00810      pblk = (THD_datablock *) btype ;          /* datablock pblk  */
00811      if( ! ISVALID_DATABLOCK(pblk) ) EXRETURN ;
00812    } else {
00813      itype = (int *) btype ;
00814    }
00815 
00816    nx    = dblk->diskptr->dimsizes[0] ;
00817    ny    = dblk->diskptr->dimsizes[1] ;
00818    nz    = dblk->diskptr->dimsizes[2] ;
00819    nvals = dblk->nvals ; if( nvals < 1 ) EXRETURN ; /* something wrong */
00820 
00821    /** make brick information arrays, if not pre-existing **/
00822 
00823    if( dblk->brick_bytes == NULL ){
00824 STATUS("making dblk->brick_bytes") ;
00825      dblk->brick_bytes = (int *) XtMalloc( sizeof(int) * nvals ) ;
00826    }
00827 
00828    if( dblk->brick_fac == NULL ){
00829 STATUS("making dblk->brick_fac") ;
00830      dblk->brick_fac = (float *) XtMalloc( sizeof(float) * nvals ) ;
00831      for( ibr=0 ; ibr < nvals ; ibr++ )
00832        dblk->brick_fac[ibr] = (ntype < 0) ? pblk->brick_fac[ibr] : 0.0 ;
00833    }
00834 
00835    dblk->total_bytes = 0 ;
00836 
00837    if( dblk->brick != NULL ){
00838 STATUS("destroying old dblk->brick") ;
00839      DESTROY_IMARR( dblk->brick ) ;
00840    }
00841 
00842 STATUS("making new dblk->brick") ;
00843    INIT_IMARR( dblk->brick ) ;  /* make the new brick */
00844 
00845    /** set up each sub-brick **/
00846 
00847 STATUS("starting sub-brick creations") ;
00848    for( ibr=0 ; ibr < nvals ; ibr++ ){
00849       if( ntype < 0 ){     typ = DBLK_BRICK_TYPE(pblk,ibr) ;
00850       } else if( itype == NULL ){
00851                            typ = ntype ;  /* all types are the same */
00852       } else {
00853          if( ibr < ntype ) typ = itype[ibr] ;     /* types may vary */
00854          else              typ = itype[ntype-1] ;
00855       }
00856 
00857       qim = mri_new_vol_empty( nx,ny,nz , typ ) ;  /* image with no data */
00858       ADDTO_IMARR( dblk->brick , qim ) ;
00859 
00860       dblk->brick_bytes[ibr] = qim->pixel_size * qim->nvox ;
00861       dblk->total_bytes     += dblk->brick_bytes[ibr] ;
00862    }
00863 
00864 STATUS("exiting") ;
00865    EXRETURN ;
00866 }

void THD_init_datablock_keywords THD_datablock  
 

Definition at line 140 of file thd_auxdata.c.

References THD_datablock::brick_keywords, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, and XtMalloc.

Referenced by EDIT_add_bricklist(), MAKER_4D_to_typed_fbuc(), THD_append_datablock_keywords(), THD_copy_datablock_auxdata(), THD_datablock_apply_atr(), THD_datablock_from_atr(), and THD_store_datablock_keywords().

00141 {
00142    int ibr , nvals ;
00143 
00144    if( ! ISVALID_DATABLOCK(dblk) ) return ;
00145 
00146    nvals = dblk->nvals ;
00147 
00148    if( dblk->brick_keywords != NULL ){
00149       for( ibr=0 ; ibr < nvals ; ibr++ ) myXtFree( dblk->brick_keywords[ibr] ) ;
00150       myXtFree( dblk->brick_keywords ) ;
00151    }
00152 
00153    dblk->brick_keywords = (char **) XtMalloc( sizeof(char *) * nvals ) ;
00154    for( ibr=0 ; ibr < nvals ; ibr++ ){
00155       dblk->brick_keywords[ibr]    = (char *) XtMalloc(sizeof(char)*4) ;
00156       dblk->brick_keywords[ibr][0] = '\0' ;
00157    }
00158 
00159    return ;
00160 }

void THD_init_datablock_labels THD_datablock  
 

Definition at line 93 of file thd_auxdata.c.

References THD_datablock::brick_lab, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, and XtMalloc.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), EDIT_add_bricklist(), MAKER_4D_to_typed_fbuc(), THD_copy_datablock_auxdata(), THD_datablock_apply_atr(), THD_datablock_from_atr(), and THD_store_datablock_label().

00094 {
00095    int ibr , nvals ;
00096 
00097    if( ! ISVALID_DATABLOCK(dblk) ) return ;
00098 
00099    nvals = dblk->nvals ;
00100 
00101    if( dblk->brick_lab != NULL ){
00102       for( ibr=0 ; ibr < nvals ; ibr++ ) myXtFree( dblk->brick_lab[ibr] ) ;
00103       myXtFree( dblk->brick_lab ) ;
00104    }
00105 
00106    dblk->brick_lab = (char **) XtMalloc( sizeof(char *) * nvals ) ;
00107    for( ibr=0 ; ibr < nvals ; ibr++ ){
00108       dblk->brick_lab[ibr] = (char *) XtMalloc(sizeof(char)*8) ;
00109       sprintf( dblk->brick_lab[ibr] , "#%d" , ibr ) ;
00110    }
00111 
00112    return ;
00113 }

void THD_init_datablock_stataux THD_datablock  
 

Definition at line 199 of file thd_auxdata.c.

References THD_datablock::brick_stataux, THD_datablock::brick_statcode, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, and XtMalloc.

Referenced by MAKER_4D_to_typed_fbuc(), THD_copy_datablock_auxdata(), and THD_store_datablock_stataux().

00200 {
00201    int ibr , nvals ;
00202 
00203    if( ! ISVALID_DATABLOCK(dblk) ) return ;
00204 
00205    nvals = dblk->nvals ;
00206 
00207    if( dblk->brick_statcode != NULL )
00208       myXtFree( dblk->brick_statcode ) ;
00209 
00210    if( dblk->brick_stataux != NULL ){
00211       for( ibr=0 ; ibr < nvals ; ibr++ ) myXtFree( dblk->brick_stataux[ibr] ) ;
00212       myXtFree( dblk->brick_stataux ) ;
00213    }
00214 
00215    /* initialize to emptinesss */
00216 
00217    dblk->brick_statcode = (int *)    XtMalloc( sizeof(int)     * nvals ) ;
00218    dblk->brick_stataux  = (float **) XtMalloc( sizeof(float *) * nvals ) ;
00219    for( ibr=0 ; ibr < nvals ; ibr++ ){
00220       dblk->brick_statcode[ibr] = 0 ;
00221       dblk->brick_stataux[ibr]  = NULL ;
00222    }
00223 
00224    return ;
00225 }

void THD_init_diskptr_names THD_diskptr   dkptr,
char *    dirname,
char *    headname,
char *    prefixname,
int    view_type,
Boolean    do_datafiles
 

Initialize the names inside a diskptr 29 Feb 2001: modified to take directory from prefixname as well as from dirname - RWCox. 12 May 2003: if prefixname starts with '/', then dirname will be ignored - RWCox. -----------------------------------------------------------------

Definition at line 18 of file thd_initdkptr.c.

References THD_diskptr::brick_name, DATASET_BRICK_SUFFIX, DATASET_HEADER_SUFFIX, THD_diskptr::directory_name, ENTRY, THD_diskptr::filecode, FIRST_VIEW_TYPE, THD_diskptr::header_name, ISVALID_DISKPTR, LAST_VIEW_TYPE, MCW_strncpy, THD_diskptr::prefix, PREFIX_VIEW_TO_FILECODE, THD_MAX_NAME, THD_MAX_PREFIX, THD_MAX_VIEWCODE, and THD_diskptr::viewcode.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), duplicate_dataset(), EDIT_dset_items(), EDIT_empty_copy(), EDIT_empty_datablock(), main(), r_new_resam_dset(), THD_datablock_from_atr(), and THD_write_3dim_dataset().

00022 {
00023    int ii ;
00024    Boolean redo_filecode = False ;
00025    char dname[THD_MAX_NAME]="\0" , pname[THD_MAX_PREFIX]="\0" ; /* 29 Feb 2001 */
00026 
00027 ENTRY("THD_init_diskptr_names") ;
00028 
00029    if( ! ISVALID_DISKPTR(dkptr) ) EXRETURN ;
00030 
00031    /* 29 Feb 2001: put dirname and any directories in prefixname together */
00032 
00033    if( dirname != NULL && (ii=strlen(dirname)) > 0 ){
00034       MCW_strncpy(dname,dirname,THD_MAX_NAME-2) ;
00035       if( dname[ii-1] != '/' ){ dname[ii] = '/'; dname[ii+1] = '\0'; }
00036    }
00037 
00038    if( prefixname != NULL ){
00039       if( strstr(prefixname,"/") != NULL ){
00040          int lp = strlen(prefixname) , jj , ld ;
00041          for( ii=lp-1 ; ii >= 0 && prefixname[ii] != '/' ; ii-- ) ; /* find last '/' */
00042          if( ii >= 0 ){  /* should always be true */
00043             ld = strlen(dname) ; if( prefixname[0] == '/' ) ld = 0 ;
00044             memcpy(dname+ld,prefixname,ii+1) ; dname[ld+ii+1] = '\0' ;
00045             MCW_strncpy(pname,prefixname+ii+1,THD_MAX_PREFIX) ;
00046          } else {
00047             MCW_strncpy(pname,prefixname,THD_MAX_PREFIX) ; /* should never transpire */
00048          }
00049       } else {
00050          MCW_strncpy(pname,prefixname,THD_MAX_PREFIX) ;
00051       }
00052    }
00053 
00054    /*-- rewrite directory name? --*/
00055 
00056    if( (ii=strlen(dname)) > 0 ){
00057       MCW_strncpy( dkptr->directory_name , dname , THD_MAX_NAME ) ;
00058       if( dkptr->directory_name[ii-1] != '/' ){
00059          dkptr->directory_name[ii]   = '/' ;
00060          dkptr->directory_name[ii+1] = '\0' ;
00061       }
00062    }
00063 
00064    /*-- rewrite viewcode? --*/
00065 
00066    if( view_type >= FIRST_VIEW_TYPE && view_type <= LAST_VIEW_TYPE ){
00067       MCW_strncpy( dkptr->viewcode , VIEW_codestr[view_type] , THD_MAX_VIEWCODE ) ;
00068       redo_filecode = True ;
00069    }
00070 
00071    /*-- rewrite prefix? --*/
00072 
00073    if( strlen(pname) > 0 ){
00074       MCW_strncpy( dkptr->prefix , pname , THD_MAX_PREFIX ) ;
00075       redo_filecode = True ;
00076    }
00077 
00078    /*-- if either viewcode or prefix changed, alter filecode --*/
00079 
00080    if( redo_filecode ){
00081       PREFIX_VIEW_TO_FILECODE( dkptr->prefix, dkptr->viewcode, dkptr->filecode ) ;
00082    }
00083 
00084    /*-- rewrite header_name --*/
00085 
00086    if( headname != NULL && strlen(headname) > 0 ){
00087       MCW_strncpy( dkptr->header_name , headname , THD_MAX_NAME ) ;
00088    } else {
00089       sprintf( dkptr->header_name , "%s%s.%s" ,
00090                dkptr->directory_name,dkptr->filecode,DATASET_HEADER_SUFFIX ) ;
00091    }
00092 
00093    /*-- if desired, create the datafile names as well --*/
00094 
00095    if( do_datafiles ){
00096 
00097       sprintf( dkptr->brick_name , "%s%s.%s",
00098                dkptr->directory_name,dkptr->filecode,DATASET_BRICK_SUFFIX ) ;
00099 
00100    }
00101    EXRETURN ;
00102 }

THD_datablock* THD_init_one_datablock char *   ,
char *   
 

Definition at line 19 of file thd_initdblk.c.

References ADDTO_KILL, AFNI_yesenv(), THD_datablock::brick, THD_datablock::brick_bytes, THD_datablock::brick_fac, THD_datablock::brick_keywords, THD_datablock::brick_lab, THD_datablock::brick_stataux, THD_datablock::brick_statcode, THD_diskptr::byte_order, DATABLOCK_MEM_UNDEFINED, DATABLOCK_TYPE, DATASET_HEADER_SUFFIX, DBLK_unlock, THD_diskptr::dimsizes, THD_datablock::diskptr, DISKPTR_TYPE, EDIT_empty_datablock(), ENTRY, FILENAME_TO_PREFIX, getenv(), INIT_KILL, THD_datablock::kl, LSB_FIRST_STRING, THD_datablock::malloc_type, THD_datablock::master_bot, THD_datablock::master_bytes, THD_datablock::master_ival, THD_datablock::master_nvals, THD_datablock::master_top, mri_short_order(), MSB_FIRST_STRING, myXtFree, myXtNew, native_order, no_mmap, no_ordwarn, THD_diskptr::nvals, ORDER_LEN, THD_datablock::parent, THD_diskptr::rank, RETURN, THD_datablock::shm_idcode, STATUS, THD_diskptr::storage_mode, STORAGE_UNDEFINED, THD_datablock_from_atr(), THD_delete_datablock(), THD_MAX_NAME, THD_read_all_atr(), THD_datablock::total_bytes, THD_datablock::type, and THD_diskptr::type.

Referenced by THD_init_prefix_datablocks(), and THD_open_one_dataset().

00020 {
00021    THD_datablock *dblk ;
00022    THD_diskptr   *dkptr ;
00023    int ii ;
00024    char prefix[THD_MAX_NAME] = "\0" ;
00025    int default_order ;   /* 21 Jun 2000 */
00026 
00027 ENTRY("THD_init_one_datablock") ;
00028 
00029    /*-- sanity checks --*/
00030 
00031    if( dirname  == NULL || strlen(dirname)  == 0 ||
00032        headname == NULL || strlen(headname) == 0   ) RETURN( NULL ) ;
00033 
00034    FILENAME_TO_PREFIX(headname,prefix) ;
00035    if( strlen(prefix) == 0 ||
00036        strstr(headname,DATASET_HEADER_SUFFIX) == NULL ) RETURN( NULL ) ;
00037 
00038    /*-- byte ordering stuff --*/
00039 
00040    if( native_order < 0 ) native_order = mri_short_order() ;
00041 
00042    no_mmap    = AFNI_yesenv("AFNI_NOMMAP") ;
00043    no_ordwarn = AFNI_yesenv("AFNI_NO_BYTEORDER_WARNING") ;
00044 
00045    { char *hh = getenv("AFNI_BYTEORDER_INPUT") ;    /* 21 Jun 2000 */
00046      default_order = native_order ;
00047      if( hh != NULL ){
00048        if( strncmp(hh,LSB_FIRST_STRING,ORDER_LEN) == 0 )
00049          default_order = LSB_FIRST ;
00050        else if( strncmp(hh,MSB_FIRST_STRING,ORDER_LEN) == 0 )
00051          default_order = MSB_FIRST ;
00052      }
00053    }
00054 
00055 #if 1
00056 
00057    dblk  = EDIT_empty_datablock() ;    /* 11 Mar 2005 -- the new way */
00058    dkptr = dblk->diskptr ;
00059 
00060 #else
00061    /*-- create output datablock (the old way) --*/
00062 
00063    dblk              = myXtNew( THD_datablock ) ;
00064    dblk->type        = DATABLOCK_TYPE ;
00065    dblk->brick       = NULL ;  /* will be filled in below */
00066    dblk->brick_bytes = NULL ;  /* ditto */
00067    dblk->brick_fac   = NULL ;  /* ditto */
00068    dblk->total_bytes = 0 ;     /* ditto */
00069    dblk->malloc_type = DATABLOCK_MEM_UNDEFINED ;
00070    dblk->parent      = NULL ;
00071 
00072    dblk->brick_lab      = NULL ;  /* 30 Nov 1997 */
00073    dblk->brick_keywords = NULL ;
00074    dblk->brick_statcode = NULL ;
00075    dblk->brick_stataux  = NULL ;
00076 
00077    dblk->master_nvals = 0 ;     /* 11 Jan 1999 */
00078    dblk->master_ival  = NULL ;
00079    dblk->master_bytes = NULL ;
00080 
00081    dblk->master_bot = 1.0 ;     /* 21 Feb 2001 */
00082    dblk->master_top = 0.0 ;
00083 
00084    DBLK_unlock(dblk) ;  /* Feb 1998 */
00085 
00086    dblk->shm_idcode[0] = '\0' ;  /* 02 May 2003 */
00087 
00088    INIT_KILL(dblk->kl) ;
00089 
00090    dblk->diskptr       = dkptr = myXtNew( THD_diskptr ) ;
00091    dkptr->type         = DISKPTR_TYPE ;
00092    dkptr->storage_mode = STORAGE_UNDEFINED ;
00093 #if 0
00094    dkptr->byte_order   = native_order ;  /* 25 April 1998 */
00095 #else
00096    dkptr->byte_order   = default_order;  /* 21 June 2000 */
00097 #endif
00098 
00099    ADDTO_KILL(dblk->kl,dkptr) ;
00100 
00101 #endif  /* end of initializing empty datablock and diskptr */
00102 
00103    /*-- read attributes from disk, store in the datablock --*/
00104 
00105    THD_read_all_atr( headname , dblk ) ;
00106 
00107    /*-- 09 Mar 2005: all the attribute processing is moved away --*/
00108 
00109    ii = THD_datablock_from_atr( dblk, dirname, headname ) ;
00110    if( ii == 0 ){
00111      THD_delete_datablock( dblk ) ;
00112      myXtFree(dblk) ;
00113      RETURN( NULL ) ;
00114    }
00115 
00116 #if 0
00117    if( PRINT_TRACING ){
00118      char str[256] ;
00119      sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d",
00120              dkptr->rank , dkptr->nvals ,
00121              dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] ) ;
00122      STATUS(str) ;
00123    }
00124 #endif
00125 
00126    RETURN( dblk ) ;
00127 }

THD_datablock_array* THD_init_prefix_datablocks char *   ,
THD_string_array  
 

Definition at line 17 of file thd_initprefix.c.

References ADDTO_DBARR, THD_string_array::ar, DATASET_HEADER_SUFFIX, FILENAME_TO_PREFIX, INIT_DBARR, THD_string_array::num, REMOVEFROM_SARR, SARR_lookfor_substring(), THD_init_one_datablock(), and THD_MAX_NAME.

Referenced by THD_init_alldir_datablocks().

00019 {
00020    THD_datablock_array * dblk_arr ;
00021    THD_datablock       * dblk ;
00022    int nlast , nnext , plen , ii ;
00023    char prefixcode[THD_MAX_NAME] , dirname[THD_MAX_NAME] , ptemp[THD_MAX_NAME] ;
00024    char * fname ;
00025 
00026    /* initialize answer */
00027 
00028    INIT_DBARR( dblk_arr ) ;
00029 
00030    if( prefixname   == NULL || strlen(prefixname) == 0 ||
00031        regfile_list == NULL || regfile_list->num  <= 0   ) return dblk_arr ;
00032 
00033    strcpy(prefixcode,prefixname) ; strcat(prefixcode,"+") ;
00034 
00035    /* for each file that could be a dataset header, try to make a datablock */
00036 
00037    nlast = 0 ;  /* start first search at beginning of list */
00038 
00039    do{
00040 
00041       /* look for the correct type of filename */
00042 
00043       nnext = SARR_lookfor_substring( regfile_list ,
00044                                       DATASET_HEADER_SUFFIX , nlast ) ;
00045 
00046       if( nnext < 0 ) break ;  /* no more header files */
00047       nlast = nnext + 1 ;      /* start next search here */
00048 
00049       fname = regfile_list->ar[nnext] ;
00050       if( strstr(fname,prefixcode) == NULL ) continue ; /* wrong prefix */
00051       FILENAME_TO_PREFIX(fname,ptemp) ;
00052       if( strcmp(prefixname,ptemp) != 0 ) continue ;    /* wrong prefix */
00053 
00054       /* try to make datablock from this file */
00055 
00056       /*-- find directory in fname --*/
00057 
00058       plen = strlen(fname) ;
00059       for( ii=plen-1 ; ii >= 0 ; ii-- ) if( fname[ii] == '/' ) break ;
00060 
00061       if( ii < 0 ){
00062          strcpy( dirname , "./" ) ;      /* fake directory name */
00063       } else {
00064          strcpy( dirname , fname ) ;
00065          dirname[ii+1] = '\0' ;
00066       }
00067 
00068       /* try to make datablock from this file */
00069 
00070       dblk = THD_init_one_datablock( dirname , fname ) ;
00071       if( dblk != NULL ) ADDTO_DBARR(dblk_arr,dblk) ;
00072       REMOVEFROM_SARR( regfile_list , nnext ) ;
00073 
00074    } while(1) ;
00075 
00076    return dblk_arr ;
00077 }

THD_session* THD_init_session char *   
 

Definition at line 18 of file thd_initsess.c.

References addto_Htable(), ADN_none, ADN_xyzdel, ADN_xyzorient, AFMALL, AFNI_concatenate_warp(), AFNI_make_affwarp_12(), AFNI_make_affwarp_mat(), AFNI_noenv(), XtPointer_array::ar, THD_3dim_dataset_array::ar, BLANK_SESSION, THD_3dim_dataset::daxes, DSET_PREFIX, THD_session::dsset, DUMP_LMAP, EDIT_dset_items(), ENTRY, free, FREE_3DARR, FREE_DBARR, FREE_XTARR, THD_3dim_dataset::idcode, THD_ivec3::ijk, ISANAT, ISFUNC, ISVALID_DSET, THD_session::lastname, LOAD_MAT, MAT_INV, MCW_file_expand(), MCW_free_expand(), MCW_strncpy, MCW_wildcards(), mmm, my_getenv(), myXtFree, myXtNew, new_Htable(), XtPointer_array::num, THD_datablock_array::num, THD_3dim_dataset_array::num, THD_session::num_dsset, ORIENT_OPPOSITE, THD_session::parent, RETURN, THD_warp::rig_bod, s2, THD_3dim_dataset::self_name, SESSION_TYPE, THD_session::sessname, SNGL_mat_to_dicomm(), STATUS, MCW_idcode::str, THD_array_3dim_from_block(), THD_delete_3dim_dataset(), THD_init_alldir_datablocks(), THD_is_directory(), THD_MAX_NAME, THD_MAX_SESSION_SIZE, THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), THD_open_minc(), THD_open_mpeg(), THD_open_nifti(), THD_order_session(), THD_trailname(), TRANSPOSE_MAT, tt, THD_session::type, UNLOAD_MAT, THD_3dim_dataset::view_type, THD_affine_warp::warp, THD_session::warptable, THD_dataxes::xxdel, THD_dataxes::xxorient, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorient, THD_dataxes::zzdel, and THD_dataxes::zzorient.

Referenced by AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), and AFNI_rescan_session_OLD().

00019 {
00020    THD_session            * sess ;
00021    XtPointer_array        * dblk_arrarr ;
00022    THD_datablock_array    * dblk_arr ;
00023    THD_3dim_dataset       * dset ;
00024    THD_3dim_dataset_array * dset_arr ;
00025 
00026    int ibar , idset , iview  , nds ;
00027 
00028 ENTRY("THD_init_session") ;
00029 
00030    /*-- sanity check --*/
00031 
00032    if( sessname == NULL || strlen(sessname) == 0 || !THD_is_directory(sessname) )
00033      RETURN( NULL ) ;
00034 
00035    /*-- initialize session --*/
00036 
00037    sess         = myXtNew( THD_session ) ;
00038    sess->type   = SESSION_TYPE ;
00039    sess->parent = NULL ;
00040    BLANK_SESSION(sess) ;  /* null out all entries */
00041 
00042    /* save directory name, with a trailing slash */
00043 
00044    MCW_strncpy( sess->sessname , sessname , THD_MAX_NAME ) ;
00045    iview = strlen(sess->sessname) ;
00046    if( sess->sessname[iview-1] != '/' ){  /* tack trailing / onto sessname */
00047      sess->sessname[iview]   = '/' ;
00048      sess->sessname[iview+1] = '\0' ;
00049    } else {
00050      iview-- ;  /* iview now points to last non-NUL character in string */
00051    }
00052 
00053    /* save last name from sessname */
00054 #if 1
00055    { char * env = my_getenv( "AFNI_SESSTRAIL" ) ; int tt = 0 ;
00056      if( env != NULL ) tt = strtol(env,NULL,10) ;
00057      env = THD_trailname(sess->sessname,tt) ;
00058      tt = 1+strlen(env) - THD_MAX_NAME ; if( tt < 0 ) tt = 0 ;
00059      strcpy( sess->lastname , env+tt ) ;
00060    }
00061 #else
00062      for( iview-- ; iview >= 0 ; iview-- )
00063        if( sess->sessname[iview] == '/' ) break ;
00064      MCW_strncpy( sess->lastname, &(sess->sessname[iview+1]), THD_MAX_NAME ) ;
00065 #endif
00066 
00067    /*-- read all datablocks --*/
00068 
00069    dblk_arrarr = THD_init_alldir_datablocks( sess->sessname ) ;
00070 
00071    /*-- for each datablock array ... --*/
00072 
00073    for( ibar=0 ; ibar < dblk_arrarr->num ; ibar++ ){
00074 
00075       /*-- get the current array of datablocks --*/
00076 
00077       dblk_arr = (THD_datablock_array *) dblk_arrarr->ar[ibar] ;
00078       if( dblk_arr == NULL || dblk_arr->num <= 0 ) continue ;    /* huh? */
00079 
00080       /*-- convert it into an array of datasets --*/
00081 
00082       dset_arr = THD_array_3dim_from_block( dblk_arr ) ;
00083       if( dset_arr == NULL || dset_arr->num <= 0 ) continue ;
00084 
00085       /*-- place it into the next row of the THD_session [28 Jul 2003] --*/
00086 
00087       nds = sess->num_dsset ;
00088 
00089       if( nds >= THD_MAX_SESSION_SIZE ){   /* bad! */
00090         fprintf(stderr,
00091          "\n*** Session %s table overflow with dataset %s ***\n",
00092              sessname , dset_arr->ar[0]->self_name) ;
00093         for( idset=0 ; idset < dset_arr->num ; idset++ )
00094           THD_delete_3dim_dataset( dset_arr->ar[idset] , False ) ;
00095         FREE_3DARR(dset_arr) ;
00096         continue ;  /* skip to next dblk_arr (ibar loop) */
00097       }
00098 
00099       /*-- put each dataset into this row in its view place --*/
00100 
00101       for( idset=0 ; idset < dset_arr->num ; idset++ ){
00102         dset  = dset_arr->ar[idset] ;
00103         iview = dset->view_type ;
00104 
00105         if( sess->dsset[nds][iview] != NULL ){  /* should never happen */
00106           fprintf(stderr,
00107            "\n*** Session %s has duplicate dataset views of %s ***\n",
00108            sessname , dset->self_name) ;
00109           THD_delete_3dim_dataset( dset , False ) ;
00110         } else {
00111           sess->dsset[nds][iview] = dset ;       /* should always happen */
00112         }
00113       }
00114 
00115       sess->num_dsset ++ ;  /* one more row */
00116 
00117       FREE_3DARR(dset_arr) ;
00118 
00119    } /* end of loop over each datablock array (ibar) */
00120 
00121    /*-- throw away the datablock arrays at this point --*/
00122 
00123    STATUS("trashing dblk_arrarr") ;
00124 
00125    for( ibar=0 ; ibar < dblk_arrarr->num ; ibar++ ){
00126      dblk_arr = (THD_datablock_array *) dblk_arrarr->ar[ibar] ;
00127      FREE_DBARR( dblk_arr ) ;
00128    }
00129    FREE_XTARR( dblk_arrarr ) ;
00130 
00131    /*-- 29 Oct 2001: try to read .mnc "datasets" --*/
00132 
00133    if( !AFNI_noenv("AFNI_MINC_DATASETS") ){
00134      char ename[THD_MAX_NAME] , **fn_minc , *eee ;
00135      int num_minc , ii ;
00136 
00137      STATUS("looking for MINC files") ;
00138 
00139      strcpy(ename,sess->sessname) ; strcat(ename,"*.mnc") ;
00140      eee = ename ;
00141      MCW_file_expand( 1,&eee , &num_minc,&fn_minc ) ;  /* find files */
00142 
00143      if( num_minc > 0 ){                               /* got some! */
00144        STATUS("opening MINC files") ;
00145        for( ii=0 ; ii < num_minc ; ii++ ){             /* loop over files */
00146          dset = THD_open_minc( fn_minc[ii] ) ;         /* try it on */
00147          if( !ISVALID_DSET(dset) ) continue ;          /* doesn't fit? */
00148          nds = sess->num_dsset ;
00149          if( nds >= THD_MAX_SESSION_SIZE ){
00150            fprintf(stderr,
00151              "\n*** Session %s table overflow with MINC dataset %s ***\n",
00152              sessname , fn_minc[ii] ) ;
00153            THD_delete_3dim_dataset( dset , False ) ;
00154            break ; /* out of for loop */
00155          }
00156          iview = dset->view_type ;
00157          sess->dsset[nds][iview] = dset ;
00158          sess->num_dsset ++ ;
00159        } /* end of loop over files */
00160        MCW_free_expand( num_minc , fn_minc ) ;
00161      } /* end of if we found MINC files */
00162    }
00163 
00164    /*-- 06 Apr 2005: try to read NIfTI-1 files [KRH and RWC] --*/
00165 
00166    if( !AFNI_noenv("AFNI_NIFTI_DATASETS") ){
00167      char *ename[2] , **fn_nifti ;
00168      int num_nifti , ii ;
00169 
00170      STATUS("looking for NIFTI files") ;
00171 
00172      ename[0] = AFMALL(char, THD_MAX_NAME) ;
00173      ename[1] = AFMALL(char, THD_MAX_NAME) ;
00174      strcpy(ename[0],sess->sessname) ; strcat(ename[0],"*.nii") ;
00175      strcpy(ename[1],sess->sessname) ; strcat(ename[1],"*.nii.gz") ;
00176      MCW_file_expand( 2,ename , &num_nifti,&fn_nifti ) ;  /* find files */
00177      free(ename[0]) ; free(ename[1]) ;
00178 
00179      if( num_nifti > 0 ){                               /* got some! */
00180        STATUS("opening NIFTI files") ;
00181        for( ii=0 ; ii < num_nifti ; ii++ ){             /* loop over files */
00182          dset = THD_open_nifti( fn_nifti[ii] ) ;        /* try it on */
00183          if( !ISVALID_DSET(dset) ) continue ;           /* doesn't fit? */
00184          nds = sess->num_dsset ;
00185          if( nds >= THD_MAX_SESSION_SIZE ){
00186            fprintf(stderr,
00187              "\n*** Session %s table overflow with NIfTI dataset %s ***\n",
00188              sessname , fn_nifti[ii] ) ;
00189            THD_delete_3dim_dataset( dset , False ) ;
00190            break ; /* out of for loop */
00191          }
00192          iview = dset->view_type ;
00193          sess->dsset[nds][iview] = dset ;
00194          sess->num_dsset ++ ;
00195        } /* end of loop over files */
00196        MCW_free_expand( num_nifti , fn_nifti ) ;
00197      } /* end of if we found NIFTI files */
00198    }
00199 
00200    /*-- 27 Aug 2002: try to read any ANALYZE "datasets" here --*/
00201 
00202    if( !AFNI_noenv("AFNI_ANALYZE_DATASETS") ){
00203      char *ename[2] , **fn_anlz ;
00204      int num_anlz , ii , nee ;
00205 #ifdef ALLOW_FSL_FEAT
00206      int feat_exf=-1 , feat_hrs=-1 , feat_std=-1 ;
00207      int feat_nds_start=sess->num_dsset ;
00208 #endif
00209 
00210      STATUS("looking for ANALYZE files") ;
00211 
00212      ename[0] = AFMALL(char, THD_MAX_NAME) ;
00213      strcpy(ename[0],sess->sessname) ; strcat(ename[0],"*.hdr") ;
00214      nee = 1 ;
00215 #ifdef ALLOW_FSL_FEAT
00216      ename[1] = AFMALL(char, THD_MAX_NAME) ;
00217      strcpy(ename[1],sess->sessname) ; strcat(ename[1],"stats/*stat*.hdr") ;
00218      nee++ ;
00219 #endif
00220      MCW_file_expand( nee,ename , &num_anlz,&fn_anlz ) ;  /* find files */
00221      for( ii=0 ; ii < nee ; ii++ ) free(ename[ii]) ;
00222 
00223      if( num_anlz > 0 ){                               /* got some! */
00224        STATUS("opening ANALYZE files") ;
00225        for( ii=0 ; ii < num_anlz ; ii++ ){             /* loop over files */
00226          dset = THD_open_analyze( fn_anlz[ii] ) ;      /* try it on */
00227          if( !ISVALID_DSET(dset) ) continue ;          /* doesn't fit? */
00228          nds = sess->num_dsset ;
00229          if( nds >= THD_MAX_SESSION_SIZE ){
00230            fprintf(stderr,
00231              "\n*** Session %s table overflow with ANALYZE dataset %s ***\n",
00232              sessname , fn_anlz[ii] ) ;
00233            THD_delete_3dim_dataset( dset , False ) ;
00234            break ; /* out of for loop */
00235         }
00236         iview = dset->view_type ;
00237         sess->dsset[nds][iview] = dset ;
00238         sess->num_dsset ++ ;
00239 #ifdef ALLOW_FSL_FEAT
00240              if( strcmp(DSET_PREFIX(dset),"example_func.hdr") == 0 ) feat_exf = nds;
00241         else if( strcmp(DSET_PREFIX(dset),"highres.hdr")      == 0 ) feat_hrs = nds;
00242         else if( strcmp(DSET_PREFIX(dset),"standard.hdr")     == 0 ) feat_std = nds;
00243 #endif
00244        } /* end of loop over files */
00245 
00246        MCW_free_expand( num_anlz , fn_anlz ) ;  /* free file list */
00247 
00248        /* now read in linear mappings (.mat files) for FSL FEAT */
00249 
00250 #ifdef ALLOW_FSL_FEAT
00251        if( feat_exf >= 0                        &&
00252            sess->num_dsset - feat_nds_start > 0 &&
00253            (feat_hrs >= 0 || feat_std >= 0)       ){  /* found FEAT files */
00254 
00255          THD_3dim_dataset *dset_exf=NULL, *dset_hrs=NULL, *dset_std=NULL ;
00256          char fnam[THD_MAX_NAME] ;
00257          FILE *fp ;
00258          float a11,a12,a13,s1 , a21,a22,a23,s2 , a31,a32,a33,s3 ;
00259          THD_warp *warp_exf_hrs=NULL , *warp_exf_std=NULL , *warp_std_hrs=NULL ;
00260 
00261                              dset_exf = sess->dsset[feat_exf][0] ;  /* Must have this. */
00262          if( feat_hrs >= 0 ) dset_hrs = sess->dsset[feat_hrs][0] ;  /* And at least   */
00263          if( feat_std >= 0 ) dset_std = sess->dsset[feat_std][0] ;  /* one of these. */
00264 
00265          /* try to read the warp from example_func (EPI) to standard */
00266 
00267          if( dset_std != NULL ){
00268            strcpy(fnam,sess->sessname) ; strcat(fnam,"example_func2standard.mat") ;
00269            fp = fopen(fnam,"r") ;
00270            if( fp != NULL ){
00271              ii = fscanf(fp,"%f%f%f%f %f%f%f%f %f%f%f%f" ,
00272                          &a11,&a12,&a13,&s1 , &a21,&a22,&a23,&s2 ,
00273                                               &a31,&a32,&a33,&s3   ) ;
00274              if( ii == 12 )
00275                warp_exf_std = AFNI_make_affwarp_12( a11,a12,a13,s1 ,
00276                                                     a21,a22,a23,s2 ,
00277                                                     a31,a32,a33,s3   ) ;
00278              fclose(fp) ;
00279            }
00280 
00281            /* 28 Aug 2002:
00282                (i)  correct orientation of example_func
00283                (ii) correct warp for non-DICOM order of coords in datasets      */
00284 
00285            if( warp_exf_std != NULL ){
00286              THD_mat33 mmm,nnn ;
00287              int   ix , iy , iz ;
00288              float ax , ay , az ;
00289 
00290 #if 0
00291 printf("warp_exf_std BEFORE:") ; DUMP_LMAP(warp_exf_std->rig_bod.warp) ;
00292 #endif
00293 
00294 #undef FIX_EXF
00295 #ifdef FIX_EXF
00296              /* make matrix that transforms standard to example_func */
00297 
00298              LOAD_MAT(mmm,a11,a12,a13,a21,a22,a23,a31,a32,a33) ;
00299              nnn = MAT_INV(mmm) ;
00300              UNLOAD_MAT(nnn,a11,a12,a13,a21,a22,a23,a31,a32,a33) ;
00301 
00302              /* for each for, find index and value of largest element */
00303 
00304              ix = 1 ; ax = a11 ;
00305              if( fabs(a12) > fabs(ax) ){ ix = 2 ; ax = a12 ; }
00306              if( fabs(a13) > fabs(ax) ){ ix = 3 ; ax = a13 ; }
00307 
00308              iy = 1 ; ay = a21 ;
00309              if( fabs(a22) > fabs(ay) ){ iy = 2 ; ay = a22 ; }
00310              if( fabs(a23) > fabs(ay) ){ iy = 3 ; ay = a23 ; }
00311 
00312              iz = 1 ; az = a31 ;
00313              if( fabs(a32) > fabs(az) ){ iz = 2 ; az = a32 ; }
00314              if( fabs(a33) > fabs(az) ){ iz = 3 ; az = a33 ; }
00315 #else
00316              ix = 1 ; iy = 2 ; iz = 3 ;
00317 #endif
00318 
00319              if( ix+iy+iz == 6 ){  /* (ix,iy,iz) must be a permutation of (1,2,3) */
00320                THD_ivec3 orixyz ;
00321                THD_fvec3 dxyz ;
00322                THD_dataxes *daxes = dset_exf->daxes ;
00323                THD_warp *from_exf , *to_std ;
00324 
00325 #ifdef FIX_EXF
00326                /** fix orientation of dset_exf dataset **/
00327 
00328                switch(ix){
00329                  case 1:    /* example_func x-axis is mainly same
00330                                as standard x-axis (ax>0) or its opposite (ax<0) */
00331                    if( ax > 0 ) ix = dset_std->daxes->xxorient ;
00332                    else         ix = ORIENT_OPPOSITE(dset_std->daxes->xxorient) ;
00333                  break ;
00334 
00335                  case 2:    /* example_func x-axis is mainly same
00336                                as standard y-axis (ax>0) or its opposite (ax<0) */
00337                    if( ax > 0 ) ix = dset_std->daxes->yyorient ;
00338                    else         ix = ORIENT_OPPOSITE(dset_std->daxes->yyorient) ;
00339                  break ;
00340 
00341                  case 3:    /* example_func x-axis is mainly same
00342                                as standard z-axis (ax>0) or its opposite (ax<0) */
00343                    if( ax > 0 ) ix = dset_std->daxes->zzorient ;
00344                    else         ix = ORIENT_OPPOSITE(dset_std->daxes->zzorient) ;
00345                  break ;
00346                }
00347                switch(iy){
00348                  case 1: if( ay > 0 ) iy = dset_std->daxes->xxorient ;
00349                          else         iy = ORIENT_OPPOSITE(dset_std->daxes->xxorient) ;
00350                  break ;
00351                  case 2: if( ay > 0 ) iy = dset_std->daxes->yyorient ;
00352                          else         iy = ORIENT_OPPOSITE(dset_std->daxes->yyorient) ;
00353                  break ;
00354                  case 3: if( ay > 0 ) iy = dset_std->daxes->zzorient ;
00355                          else         iy = ORIENT_OPPOSITE(dset_std->daxes->zzorient) ;
00356                  break ;
00357                }
00358                switch(iz){
00359                  case 1: if( az > 0 ) iz = dset_std->daxes->xxorient ;
00360                          else         iz = ORIENT_OPPOSITE(dset_std->daxes->xxorient) ;
00361                  break ;
00362                  case 2: if( az > 0 ) iz = dset_std->daxes->yyorient ;
00363                          else         iz = ORIENT_OPPOSITE(dset_std->daxes->yyorient) ;
00364                  break ;
00365                  case 3: if( az > 0 ) iz = dset_std->daxes->zzorient ;
00366                          else         iz = ORIENT_OPPOSITE(dset_std->daxes->zzorient) ;
00367                  break ;
00368                }
00369                orixyz.ijk[0] = ix ; orixyz.ijk[1] = iy ; orixyz.ijk[2] = iz ;
00370                dxyz.xyz[0] = fabs(daxes->xxdel) ;
00371                dxyz.xyz[1] = fabs(daxes->yydel) ;
00372                dxyz.xyz[2] = fabs(daxes->zzdel) ;
00373                if( ORIENT_sign[ix] == '-' ) dxyz.xyz[0] = -dxyz.xyz[0] ;
00374                if( ORIENT_sign[iy] == '-' ) dxyz.xyz[1] = -dxyz.xyz[1] ;
00375                if( ORIENT_sign[iz] == '-' ) dxyz.xyz[2] = -dxyz.xyz[2] ;
00376                EDIT_dset_items( dset_exf , ADN_xyzorient,orixyz, ADN_xyzdel,dxyz, ADN_none ) ;
00377 #endif
00378 
00379                /** now fix warp from example_func to standard to do it in DICOM coords **/
00380 
00381                nnn = SNGL_mat_to_dicomm( dset_exf ) ; mmm = TRANSPOSE_MAT(nnn) ;
00382                from_exf = AFNI_make_affwarp_mat( mmm ) ;
00383                nnn = SNGL_mat_to_dicomm( dset_std ) ;
00384                to_std = AFNI_make_affwarp_mat( nnn ) ;
00385                AFNI_concatenate_warp( warp_exf_std , from_exf ) ;
00386                AFNI_concatenate_warp( to_std , warp_exf_std ) ;
00387                myXtFree(warp_exf_std) ; myXtFree(from_exf) ;
00388                warp_exf_std = to_std ;
00389 
00390 #if 0
00391 printf("warp_exf_std AFTER:") ; DUMP_LMAP(warp_exf_std->rig_bod.warp) ;
00392 #endif
00393 
00394              } /* end of if warp had reasonable axis combinations */
00395            } /* end of if we got a good warp */
00396          }
00397 
00398          /* try to read the warp from example_func (EPI) to highres */
00399 
00400          if( dset_hrs != NULL ){
00401            strcpy(fnam,sess->sessname) ; strcat(fnam,"example_func2highres.mat") ;
00402            fp = fopen(fnam,"r") ;
00403            if( fp != NULL ){
00404              ii = fscanf(fp,"%f%f%f%f %f%f%f%f %f%f%f%f" ,
00405                          &a11,&a12,&a13,&s1 , &a21,&a22,&a23,&s2 ,
00406                                               &a31,&a32,&a33,&s3   ) ;
00407              if( ii == 12 )
00408                warp_exf_hrs = AFNI_make_affwarp_12( a11,a12,a13,s1 ,
00409                                                     a21,a22,a23,s2 ,
00410                                                     a31,a32,a33,s3   ) ;
00411              fclose(fp) ;
00412            }
00413 
00414            /* 28 Aug 2002: correct warp for non-DICOM order of coords in datasets */
00415 
00416            if( warp_exf_hrs != NULL ){
00417              THD_mat33 mmm,nnn ;
00418              THD_warp *from_exf , *to_hrs ;
00419 
00420 #if 0
00421 printf("warp_exf_hrs BEFORE:") ; DUMP_LMAP(warp_exf_hrs->rig_bod.warp) ;
00422 #endif
00423 
00424              nnn = SNGL_mat_to_dicomm( dset_exf ) ; mmm = TRANSPOSE_MAT(nnn) ;
00425              from_exf = AFNI_make_affwarp_mat( mmm ) ;
00426              nnn = SNGL_mat_to_dicomm( dset_hrs ) ;
00427              to_hrs = AFNI_make_affwarp_mat( nnn ) ;
00428              AFNI_concatenate_warp( warp_exf_hrs , from_exf ) ;
00429              AFNI_concatenate_warp( to_hrs , warp_exf_hrs ) ;
00430              myXtFree(warp_exf_hrs) ; myXtFree(from_exf) ;
00431              warp_exf_hrs = to_hrs ;
00432 
00433 #if 0
00434 printf("warp_exf_hrs AFTER:") ; DUMP_LMAP(warp_exf_hrs->rig_bod.warp) ;
00435 #endif
00436            }
00437          }
00438 
00439          /* try to read the warp from standard to highres */
00440 
00441          if( dset_hrs != NULL && dset_std != NULL ){
00442            strcpy(fnam,sess->sessname) ; strcat(fnam,"standard2highres.mat") ;
00443            fp = fopen(fnam,"r") ;
00444            if( fp != NULL ){
00445              ii = fscanf(fp,"%f%f%f%f %f%f%f%f %f%f%f%f" ,
00446                          &a11,&a12,&a13,&s1 , &a21,&a22,&a23,&s2 ,
00447                                               &a31,&a32,&a33,&s3   ) ;
00448              if( ii == 12 )
00449                warp_std_hrs = AFNI_make_affwarp_12( a11,a12,a13,s1 ,
00450                                                     a21,a22,a23,s2 ,
00451                                                     a31,a32,a33,s3   ) ;
00452              fclose(fp) ;
00453            }
00454 
00455            /* 28 Aug 2002: correct warp for non-DICOM order of coords in datasets */
00456 
00457            if( warp_std_hrs != NULL ){
00458              THD_mat33 mmm,nnn ;
00459              THD_warp *from_std , *to_hrs ;
00460 
00461 #if 0
00462 printf("warp_std_hrs BEFORE:") ; DUMP_LMAP(warp_std_hrs->rig_bod.warp) ;
00463 #endif
00464 
00465              nnn = SNGL_mat_to_dicomm( dset_std ) ; mmm = TRANSPOSE_MAT(nnn) ;
00466              from_std = AFNI_make_affwarp_mat( mmm ) ;
00467              nnn = SNGL_mat_to_dicomm( dset_hrs ) ;
00468              to_hrs = AFNI_make_affwarp_mat( nnn ) ;
00469              AFNI_concatenate_warp( warp_std_hrs , from_std ) ;
00470              AFNI_concatenate_warp( to_hrs , warp_std_hrs ) ;
00471              myXtFree(warp_std_hrs) ; myXtFree(from_std) ;
00472              warp_std_hrs = to_hrs ;
00473 
00474 #if 0
00475 printf("warp_std_hrs AFTER:") ; DUMP_LMAP(warp_std_hrs->rig_bod.warp) ;
00476 #endif
00477            }
00478          }
00479 
00480          /* if we have these warps,
00481             then build a hashtable describing their use in
00482             transforming funcs (in exf coords) to hrs and std coords */
00483 
00484          if( warp_exf_hrs != NULL || warp_exf_std != NULL ){
00485 
00486            if( sess->warptable == NULL )
00487               sess->warptable = new_Htable(0) ;  /* use minimum table size */
00488 
00489            if( warp_exf_hrs != NULL ){
00490              for( ii=feat_nds_start ; ii < sess->num_dsset ; ii++ ){
00491                if( ISFUNC(sess->dsset[ii][0]) ){
00492                  sprintf(fnam,"%s,%s",dset_hrs->idcode.str,sess->dsset[ii][0]->idcode.str) ;
00493                  addto_Htable( fnam , warp_exf_hrs , sess->warptable ) ;
00494                }
00495              }
00496              for( ii=feat_nds_start ; ii < sess->num_dsset ; ii++ ){
00497                if( ii != feat_hrs && ii != feat_std && ISANAT(sess->dsset[ii][0]) ){
00498                  sprintf(fnam,"%s,%s",dset_hrs->idcode.str,sess->dsset[ii][0]->idcode.str) ;
00499                  addto_Htable( fnam , warp_exf_hrs , sess->warptable ) ;
00500                }
00501              }
00502            }
00503 
00504            if( warp_exf_std != NULL ){
00505              for( ii=feat_nds_start ; ii < sess->num_dsset ; ii++ ){
00506                if( ISFUNC(sess->dsset[ii][0]) ){
00507                  sprintf(fnam,"%s,%s",dset_std->idcode.str,sess->dsset[ii][0]->idcode.str) ;
00508                  addto_Htable( fnam , warp_exf_std , sess->warptable ) ;
00509                }
00510              }
00511              for( ii=feat_nds_start ; ii < sess->num_dsset ; ii++ ){
00512                if( ii != feat_hrs && ii != feat_std && ISANAT(sess->dsset[ii][0]) ){
00513                  sprintf(fnam,"%s,%s",dset_std->idcode.str,sess->dsset[ii][0]->idcode.str) ;
00514                  addto_Htable( fnam , warp_exf_std , sess->warptable ) ;
00515                }
00516              }
00517            }
00518 
00519            if( warp_std_hrs != NULL ){
00520              sprintf(fnam,"%s,%s",dset_hrs->idcode.str,dset_std->idcode.str) ;
00521              addto_Htable( fnam , warp_std_hrs , sess->warptable ) ;
00522            }
00523 
00524          } /* end of making warptable */
00525        } /* end of FEATing */
00526 #endif
00527 
00528      } /* end of if we found ANALYZE files */
00529    }
00530 
00531    /*-- 04 Dec 2002: try to read CTF .mri and .svl "datasets" --*/
00532 
00533    if( !AFNI_noenv("AFNI_CTF_DATASETS") ){
00534      char *ename[2] , **fn_ctf ;
00535      int num_ctf , ii ;
00536 
00537      STATUS("looking for CTF files") ;
00538 
00539      ename[0] = AFMALL(char, THD_MAX_NAME) ;
00540      ename[1] = AFMALL(char, THD_MAX_NAME) ;
00541      strcpy(ename[0],sess->sessname) ; strcat(ename[0],"*.mri") ;
00542      strcpy(ename[1],sess->sessname) ; strcat(ename[1],"*.svl") ;
00543      MCW_file_expand( 2,ename , &num_ctf,&fn_ctf ) ;  /* find files */
00544      free(ename[0]) ; free(ename[1]) ;
00545 
00546      if( num_ctf > 0 ){                               /* got some files! */
00547        STATUS("opening CTF files") ;
00548        for( ii=0 ; ii < num_ctf ; ii++ ){             /* loop over files */
00549 
00550          if( strstr(fn_ctf[ii],".mri") != NULL )      /* try to read: */
00551            dset = THD_open_ctfmri( fn_ctf[ii] ) ;     /*   as MRI */
00552          else if( strstr(fn_ctf[ii],".svl") != NULL )
00553            dset = THD_open_ctfsam( fn_ctf[ii] ) ;     /*   as SAM */
00554 
00555          if( !ISVALID_DSET(dset) ) continue ;         /* doesn't read? */
00556          nds = sess->num_dsset ;
00557          if( nds >= THD_MAX_SESSION_SIZE ){
00558            fprintf(stderr,
00559             "\n*** Session %s table overflow with dataset %s ***\n",
00560             sessname , fn_ctf[ii] ) ;
00561            THD_delete_3dim_dataset( dset , False ) ;
00562            break ; /* out of for loop */
00563          }
00564          iview = dset->view_type ;
00565          sess->dsset[nds][iview] = dset ;
00566          sess->num_dsset ++ ;
00567        } /* end of loop over files */
00568        MCW_free_expand( num_ctf , fn_ctf ) ;
00569      } /* end of if we found CTF files */
00570    }
00571 
00572    /*-- 03 Dec 2001: try to read MPEG "datasets" --*/
00573 
00574    if( !AFNI_noenv("AFNI_MPEG_DATASETS") ){
00575      char ename[4*THD_MAX_NAME+64] , **fn_mpeg ;
00576      int num_mpeg , ii ;
00577 
00578      STATUS("looking for MPEG files") ;
00579 
00580      sprintf(ename,"%s*.mpg %s*.mpeg %s*.MPEG %s*.MPG" , 
00581              sess->sessname, sess->sessname, sess->sessname, sess->sessname ) ;
00582      MCW_wildcards( ename , &num_mpeg , &fn_mpeg ) ;   /* find files */
00583 
00584      if( num_mpeg > 0 ){                               /* got some! */
00585        STATUS("opening MPEG files") ;
00586        for( ii=0 ; ii < num_mpeg ; ii++ ){             /* loop over files */
00587          dset = THD_open_mpeg( fn_mpeg[ii] ) ;         /* try it on */
00588          if( !ISVALID_DSET(dset) ) continue ;          /* doesn't fit? */
00589          nds = sess->num_dsset ;
00590          if( nds >= THD_MAX_SESSION_SIZE ){
00591            fprintf(stderr,
00592              "\n*** Session %s table overflow with MPEG dataset %s ***\n",
00593              sessname , fn_mpeg[ii] ) ;
00594            THD_delete_3dim_dataset( dset , False ) ;
00595            break ; /* out of for loop */
00596          }
00597          iview = dset->view_type ;
00598          sess->dsset[nds][iview] = dset ;
00599          sess->num_dsset ++ ;
00600        } /* end of loop over files */
00601        MCW_free_expand( num_mpeg , fn_mpeg ) ;
00602      } /* end of if we found MPEG files */
00603    }
00604 
00605    /*-- done! --*/
00606 
00607    if( sess->num_dsset == 0 ){
00608       myXtFree( sess ) ; RETURN( NULL ) ;
00609    }
00610 
00611    /*-- 29 Jul 2003: order dataset rows --*/
00612 
00613    THD_order_session( sess ) ;
00614 
00615    RETURN( sess ) ;
00616 }

void THD_insert_atr THD_datablock   blk,
ATR_any   atr
 

Definition at line 670 of file thd_atr.c.

References ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, ENTRY, ATR_float::fl, ATR_int::in, ISVALID_DATABLOCK, ATR_float::name, ATR_string::name, ATR_int::name, ATR_string::nch, ATR_float::nfl, ATR_int::nin, THD_set_atr(), and ATR_any::type.

Referenced by main().

00671 {
00672 ENTRY("THD_insert_atr") ;
00673 
00674    if( ! ISVALID_DATABLOCK(blk) || atr == NULL ) EXRETURN ;
00675 
00676    switch( atr->type ){
00677 
00678      case ATR_FLOAT_TYPE:{
00679        ATR_float *aa = (ATR_float *)atr ;
00680        THD_set_atr( blk , aa->name , ATR_FLOAT_TYPE , aa->nfl , aa->fl ) ;
00681      }
00682      break ;
00683 
00684      case ATR_STRING_TYPE:{
00685        ATR_string *aa = (ATR_string *)atr ;
00686        THD_set_atr( blk , aa->name , ATR_STRING_TYPE , aa->nch , aa->ch ) ;
00687      }
00688      break ;
00689 
00690      case ATR_INT_TYPE:{
00691        ATR_int *aa = (ATR_int *)atr ;
00692        THD_set_atr( blk , aa->name , ATR_INT_TYPE , aa->nin , aa->in ) ;
00693      }
00694      break ;
00695    }
00696 
00697    EXRETURN ;
00698 }

void THD_insert_series int   ,
THD_3dim_dataset  ,
int   ,
int   ,
void *   ,
int   
 

Definition at line 23 of file thd_1Dtodset.c.

References a, THD_datablock::brick_fac, BYTEIZE, CABS, THD_3dim_dataset::dblk, DSET_ARRAY, DSET_BRICK_TYPE, DSET_IS_MALLOC, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, FAC, far, free, complex::i, ind, ISVALID_DSET, malloc, complex::r, SHORTIZE, THD_need_brick_factor(), and typ.

Referenced by main(), and THD_dataset_tshift().

00025 {
00026    int nv , ival , dtyp , ii ;
00027    float * far=NULL , * fac ;
00028 
00029    if( ind < 0                ||
00030        npt <= 0               ||
00031        dar == NULL            ||
00032        !ISVALID_DSET(dset)    ||
00033        ind >= DSET_NVOX(dset) ||
00034        !DSET_IS_MALLOC(dset)    ) return ;
00035 
00036 
00037    nv = DSET_NVALS(dset) ; if( npt > nv ) npt = nv;  /* truncate input? */
00038 
00039    if( !DSET_LOADED(dset) ) DSET_load(dset) ;        /* read from disk? */
00040    if( !DSET_LOADED(dset) ) return ;
00041 
00042    dtyp = DSET_BRICK_TYPE(dset,0) ;                  /* dataset array type */
00043 
00044    /* convert input to a floating point type */
00045 
00046    if( !raw && THD_need_brick_factor(dset) )
00047       fac = dset->dblk->brick_fac ;
00048    else
00049       raw = 1 ;
00050 
00051 #define FAC(q) ( (fac[q] != 0.0) ? 1.0/fac[q] : 1.0 )
00052 
00053    if( dtyp == MRI_complex ){                             /* complex output ?! */
00054 
00055       complex * car = (complex *) malloc( sizeof(complex) * npt ) ;
00056       complex * bar ;
00057 
00058       switch( typ ){
00059          default:
00060             free(car) ; return ;   /* bad input */
00061 
00062          case MRI_complex:
00063             memcpy( car , dar , sizeof(complex)*npt ) ;
00064          break ;
00065 
00066          case MRI_float:{
00067             float * a = (float *) dar ;
00068             for( ii=0 ; ii < npt ; ii++ ){ car[ii].r = a[ii] ; car[ii].i = 0.0 ; }
00069          }
00070          break ;
00071 
00072          case MRI_short:{
00073             short * a = (short *) dar ;
00074             for( ii=0 ; ii < npt ; ii++ ){ car[ii].r = a[ii] ; car[ii].i = 0.0 ; }
00075          }
00076          break ;
00077 
00078          case MRI_byte:{
00079             byte * a = (byte *) dar ;
00080             for( ii=0 ; ii < npt ; ii++ ){ car[ii].r = a[ii] ; car[ii].i = 0.0 ; }
00081          }
00082          break ;
00083       }
00084 
00085       /* can now copy car into dataset, and exit */
00086 
00087       if( !raw )
00088          for( ii=0 ; ii < npt ; ii++ ){ car[ii].r *= FAC(ii) ; car[ii].i *= FAC(ii) ; }
00089 
00090       for( ii=0 ; ii < npt ; ii++ ){
00091          bar = (complex *) DSET_ARRAY(dset,ii) ;
00092          bar[ind] = car[ii] ;
00093       }
00094 
00095       free(car) ; return ;
00096    }
00097 
00098    /* otherwise, compute a temporary float array */
00099 
00100    far = (float *) malloc( sizeof(float) * npt ) ;
00101    switch( typ ){
00102       default:
00103          free(far) ; return ;   /* bad input */
00104 
00105       case MRI_complex:{
00106          complex * a = (complex *) dar ;
00107          for( ii=0 ; ii < npt ; ii++ ) far[ii] = CABS(a[ii]) ;
00108       }
00109       break ;
00110 
00111       case MRI_float:
00112          memcpy( far , dar , sizeof(float)*npt ) ;
00113       break ;
00114 
00115       case MRI_short:{
00116          short * a = (short *) dar ;
00117          for( ii=0 ; ii < npt ; ii++ ) far[ii] = a[ii] ;
00118       }
00119       break ;
00120 
00121       case MRI_byte:{
00122          byte * a = (byte *) dar ;
00123          for( ii=0 ; ii < npt ; ii++ ) far[ii] = a[ii] ;
00124       }
00125       break ;
00126    }
00127 
00128    if( !raw ) for( ii=0 ; ii < npt ; ii++ ) far[ii] *= FAC(ii) ;
00129 
00130    /* now convert this to the output */
00131 
00132    switch( dtyp ){
00133 
00134       default:
00135          free(far) ; return ;   /* bad dataset? */
00136 
00137       case MRI_float:{
00138          float * bar ;
00139          for( ii=0 ; ii < npt ; ii++ ){
00140             bar = (float *) DSET_ARRAY(dset,ii) ;
00141             bar[ind] = far[ii] ;
00142          }
00143       }
00144       break ;
00145 
00146       case MRI_short:{
00147          short * bar ;
00148          for( ii=0 ; ii < npt ; ii++ ){
00149             bar = (short *) DSET_ARRAY(dset,ii) ;
00150             bar[ind] = SHORTIZE(far[ii]) ;
00151          }
00152       }
00153       break ;
00154 
00155       case MRI_byte:{
00156          byte * bar ;
00157          for( ii=0 ; ii < npt ; ii++ ){
00158             bar = (byte *) DSET_ARRAY(dset,ii) ;
00159             bar[ind] = BYTEIZE(far[ii]) ;
00160          }
00161       }
00162       break ;
00163    }
00164 
00165    free(far) ; return ;
00166 }

int THD_is_dataset char *   ,
char *   ,
int   
 

Definition at line 164 of file thd_opendset.c.

References ADN_directory_name, ADN_none, ADN_prefix, ADN_view_type, THD_3dim_dataset::dblk, THD_datablock::diskptr, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, FIRST_VIEW_TYPE, THD_diskptr::header_name, LAST_VIEW_TYPE, RETURN, THD_delete_3dim_dataset(), and THD_is_file().

Referenced by THD_open_3dcalc().

00165 {
00166    THD_3dim_dataset *dset ;
00167    int ii , vv ;
00168 
00169 ENTRY("THD_is_dataset") ;
00170 
00171    if( pname == NULL ) RETURN(-1) ;
00172 
00173    dset = EDIT_empty_copy(NULL) ;
00174    EDIT_dset_items( dset , ADN_prefix , pname , ADN_none ) ;
00175 
00176    if( sname != NULL )
00177      EDIT_dset_items( dset , ADN_directory_name , sname , ADN_none ) ;
00178 
00179    if( vt >= FIRST_VIEW_TYPE && vt <= LAST_VIEW_TYPE ){
00180      EDIT_dset_items( dset , ADN_view_type , vt , ADN_none ) ;
00181      ii = THD_is_file(dset->dblk->diskptr->header_name);
00182      THD_delete_3dim_dataset(dset,False) ;
00183      if( ii ) RETURN(vt) ;
00184      RETURN(-1) ;
00185    }
00186 
00187    for( vv=FIRST_VIEW_TYPE ; vv <= LAST_VIEW_TYPE ; vv++ ){
00188      EDIT_dset_items( dset , ADN_view_type , vv , ADN_none ) ;
00189      ii = THD_is_file(dset->dblk->diskptr->header_name);
00190      if( ii ){ THD_delete_3dim_dataset(dset,False); RETURN(vv); }
00191    }
00192 
00193    THD_delete_3dim_dataset( dset , False ) ;
00194    RETURN(-1) ;
00195 }

int THD_is_directory char *    pathname
 

Determine if this is really a directory or not.

Definition at line 510 of file Ifile.c.

00511 {
00512    static struct stat buf ; int ii ;
00513 
00514    if( pathname == NULL ) return 0 ;
00515    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00516    ii = (buf.st_mode & S_IFDIR) != 0 ; return ii ;
00517 }

int THD_is_executable char *    pathname
 

Determine if this is really an executable file or not.

Definition at line 521 of file Ifile.c.

00522 {
00523    static struct stat buf ; int ii ;
00524 
00525    if( pathname == NULL ) return 0 ;
00526    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00527    ii = (buf.st_mode & S_IXOTH) != 0 ; return ii ;
00528 }

int THD_is_file char *    pathname
 

Determine if this is really a regular file or not.

Definition at line 478 of file Ifile.c.

00479 {
00480    static struct stat buf ; int ii ;
00481 
00482    if( pathname == NULL ) return 0 ;
00483    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00484    ii = (buf.st_mode & S_IFREG) != 0 ; return ii ;
00485 }

int THD_is_ondisk char *    pathname
 

Determine if this exists at all (file, directory, ...).

Definition at line 25 of file thd_filestuff.c.

Referenced by ISQ_snapfile(), main(), THD_mkdir(), and XSAVE_output().

00026 {
00027    static struct stat buf ; int ii ;
00028 
00029    if( pathname == NULL || *pathname == '\0' ) return 0 ;
00030    ii = stat( pathname , &buf ) ;
00031    return (ii == 0) ;
00032 }

int THD_is_symlink char *    pathname
 

Determine if this is really a symbolic link or not.

Definition at line 489 of file Ifile.c.

00490 {
00491    char buf[32] ; int ii ;
00492 
00493    ii = readlink( pathname , buf , 32 ) ;
00494    return (ii > 0) ;
00495 }

void THD_linear_detrend int   ,
float *   ,
float *   ,
float *   
 

Definition at line 53 of file thd_detrend.c.

References far, and get_linear_trend().

Referenced by main(), normalize_floatvector(), and THD_dataset_tshift().

00054 {
00055    register int ii ;
00056    float f0 , f1 ;
00057 
00058    if( npt < 3 || far == NULL ) return ;
00059 
00060    get_linear_trend( npt , far , &f0 , &f1 ) ;
00061 
00062    far[0] -= f0 ;
00063    for( ii=1 ; ii < npt ; ii++ ) far[ii] -= (f0 + f1*ii) ;
00064 
00065    if( xx0 != NULL ) *xx0 = f0 ;
00066    if( xx1 != NULL ) *xx1 = f1 ;
00067 
00068    return ;
00069 }

int THD_linecount char *   
 

Definition at line 12 of file thd_linecount.c.

Referenced by PLUG_action_CB().

00013 {
00014    int nlin ;
00015    char * cpt ;
00016 
00017    if( str == NULL || str[0] == '\0' ) return 0 ;
00018 
00019    nlin = 0 ;
00020    for( cpt=str ; *cpt != '\0' ; cpt++ )
00021       if( *cpt == '\n' ) nlin++ ;
00022 
00023    if( *(cpt-1) != '\n' ) nlin++ ;
00024 
00025    return nlin ;
00026 }

void THD_load_1D THD_datablock   dblk
 

Load a 1D dataset's data into memory. Called from THD_load_datablock() in thd_loaddblk.c. -------------------------------------------------------------------

Definition at line 139 of file thd_1Ddset.c.

References AFMALL, THD_datablock::brick, THD_diskptr::brick_name, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, flip(), free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_fix_data_pointer(), MRI_FLOAT_PTR, mri_free(), mri_read_1D(), mri_transpose(), THD_diskptr::nvals, MRI_IMAGE::nx, MRI_IMAGE::ny, STORAGE_BY_1D, and THD_diskptr::storage_mode.

Referenced by THD_load_datablock().

00140 {
00141    THD_diskptr *dkptr ;
00142    MRI_IMAGE *flim ;
00143    int nxyz , nbad,iv,nv ;
00144    float *bar , *flar ;
00145    char *pn ; int lpn , flip=0 ;
00146 
00147 ENTRY("THD_load_1D") ;
00148 
00149    /*-- open input [these errors should never occur] --*/
00150 
00151    if( !ISVALID_DATABLOCK(dblk)                     ||
00152        dblk->diskptr->storage_mode != STORAGE_BY_1D ||
00153        dblk->brick == NULL                            ) EXRETURN ;
00154 
00155    dkptr = dblk->diskptr      ;
00156    nxyz  = dkptr->dimsizes[0] ;
00157    nv    = dkptr->nvals       ;
00158 
00159    if( nxyz*nv > 1000000 ) fprintf(stderr,"++ Reading %s\n",dkptr->brick_name) ;
00160 
00161    pn = strdup(dkptr->brick_name) ; lpn = strlen(pn) ;
00162    flip = (pn[lpn-1] == '\'') ;     /* 12 Jul 2005: allow for tranposing input */
00163    if( flip ) pn[lpn-1] = '\0' ;
00164 
00165    flim = mri_read_1D(pn) ; free(pn) ;
00166 
00167    if( flim == NULL ){
00168      fprintf(stderr,"** THD_load_1D(%s): can't read file!\n",dkptr->brick_name) ;
00169      EXRETURN ;
00170    }
00171    if( flip ){
00172      MRI_IMAGE *qim = mri_transpose(flim); mri_free(flim); flim = qim;
00173    }
00174 
00175    /*-- allocate space for data --*/
00176 
00177    if( nxyz != flim->nx || nv != flim->ny ){
00178      fprintf(stderr,"** THD_load_1D(%s): nx or ny mismatch!\n",dkptr->brick_name) ;
00179      fprintf(stderr,"**  expect nx=%d; got nx=%d\n",nxyz,flim->nx) ;
00180      fprintf(stderr,"**  expect ny=%d; got ny=%d\n",nv  ,flim->ny) ;
00181      mri_free(flim) ; EXRETURN ;
00182    }
00183 
00184    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00185 
00186    /** malloc space for each brick separately **/
00187 
00188    for( nbad=iv=0 ; iv < nv ; iv++ ){
00189      if( DBLK_ARRAY(dblk,iv) == NULL ){
00190        bar = AFMALL( float,  DBLK_BRICK_BYTES(dblk,iv) ) ;
00191        mri_fix_data_pointer( bar ,  DBLK_BRICK(dblk,iv) ) ;
00192        if( bar == NULL ) nbad++ ;
00193      }
00194    }
00195 
00196    /** if couldn't get them all, take our ball and go home in a snit **/
00197 
00198    if( nbad > 0 ){
00199      fprintf(stderr,"\n** failed to malloc %d 1D bricks out of %d\n\a",nbad,nv) ;
00200      for( iv=0 ; iv < nv ; iv++ ){
00201        if( DBLK_ARRAY(dblk,iv) != NULL ){
00202          free(DBLK_ARRAY(dblk,iv)) ;
00203          mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,iv) ) ;
00204        }
00205      }
00206      mri_free(flim) ; EXRETURN ;
00207    }
00208 
00209    /** copy data from image to bricks **/
00210 
00211    flar = MRI_FLOAT_PTR(flim) ;
00212 
00213    for( iv=0 ; iv < nv ; iv++ ){
00214      bar = DBLK_ARRAY(dblk,iv) ;
00215      memcpy( bar , flar + iv*nxyz , sizeof(float)*nxyz ) ;
00216    }
00217 
00218    mri_free(flim) ; EXRETURN ;
00219 }

void THD_load_3D THD_datablock   dblk
 

Load a 3D dataset's data into memory. Called from THD_load_datablock() in thd_loaddblk.c. -------------------------------------------------------------------

Definition at line 243 of file thd_3Ddset.c.

References AFMALL, THD_datablock::brick, THD_diskptr::brick_name, calloc, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_fix_data_pointer(), NI_free, NI_free_element(), NI_read_element(), NI_skip_procins(), NI_stream_close(), NI_stream_open(), THD_diskptr::nvals, STORAGE_BY_3D, THD_diskptr::storage_mode, NI_element::vec, NI_element::vec_len, and NI_element::vec_num.

Referenced by THD_load_datablock().

00244 {
00245    THD_diskptr *dkptr ;
00246    NI_element *nel ;
00247    NI_stream ns ;
00248    int nxyz , iv,nv ;
00249    char *ppp ;
00250 
00251 ENTRY("THD_load_3D") ;
00252 
00253    /*-- open input [these errors should never occur] --*/
00254 
00255    if( !ISVALID_DATABLOCK(dblk)                     ||
00256        dblk->diskptr->storage_mode != STORAGE_BY_3D ||
00257        dblk->brick == NULL                            ) EXRETURN ;
00258 
00259    dkptr = dblk->diskptr ;
00260    nxyz  = dkptr->dimsizes[0] * dkptr->dimsizes[1] * dkptr->dimsizes[2] ;
00261    nv    = dkptr->nvals ;
00262 
00263    if( nxyz*nv > 1000000 ) fprintf(stderr,"++ Reading %s\n",dkptr->brick_name) ;
00264 
00265    ppp = (char*)calloc( sizeof(char) , strlen(dkptr->brick_name)+16 ) ;
00266 
00267    strcpy(ppp,"file:") ; strcat(ppp,dkptr->brick_name) ;
00268    ns = NI_stream_open( ppp , "r" ) ; free(ppp) ;
00269    if( ns == NULL ) EXRETURN ;
00270 
00271    NI_skip_procins(1) ;
00272    nel = NI_read_element(ns,333); NI_stream_close(ns);
00273    NI_skip_procins(0) ;
00274    if( nel == NULL ) EXRETURN ;
00275 
00276    /*-- allocate space for data --*/
00277 
00278    if( nxyz != nel->vec_len || nv != nel->vec_num ){
00279      fprintf(stderr,"THD_load_3D(%s): nxyz or nv mismatch!\n",dkptr->brick_name) ;
00280      fprintf(stderr,"                 expect nxyz=%d; got %d\n",nxyz, nel->vec_len);
00281      fprintf(stderr,"                 expect nv  =%d; got %d\n",nv  , nel->vec_num);
00282      NI_free_element(nel) ; EXRETURN ;
00283    }
00284 
00285    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00286 
00287    /** malloc space for each brick separately,
00288        and copy data from element into place  **/
00289 
00290    for( iv=0 ; iv < nv ; iv++ ){
00291      if( DBLK_ARRAY(dblk,iv) == NULL ){                    /* needs data */
00292        ppp = AFMALL(char, DBLK_BRICK_BYTES(dblk,iv) );     /* make space */
00293        if( ppp == NULL ) break ;                           /* bad bad bad */
00294        mri_fix_data_pointer( ppp, DBLK_BRICK(dblk,iv) ) ;
00295        memcpy( ppp, nel->vec[iv], DBLK_BRICK_BYTES(dblk,iv) ) ;
00296        NI_free(nel->vec[iv]) ; nel->vec[iv] = NULL ;
00297      }
00298    }
00299 
00300    NI_free_element(nel) ;
00301 
00302    /* if malloc failed, then delete all bricks */
00303 
00304    if( iv < nv ){
00305      fprintf(stderr,"\n** malloc failed for 3D dataset input!\n");
00306      for( iv=0 ; iv < nv ; iv++ ){
00307        if( DBLK_ARRAY(dblk,iv) != NULL ){
00308          free( DBLK_ARRAY(dblk,iv) ) ;
00309          mri_fix_data_pointer( NULL, DBLK_BRICK(dblk,iv) ) ;
00310        }
00311      }
00312    }
00313 
00314    EXRETURN ;
00315 }

void THD_load_analyze THD_datablock   dblk
 

Load an ANALYZE dataset from disk. -----------------------------------------------------------------------

Definition at line 400 of file thd_analyzeread.c.

References AFMALL, THD_datablock::brick, THD_diskptr::brick_name, THD_diskptr::byte_order, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_NVOX, DBLK_BRICK_TYPE, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_fix_data_pointer(), mri_short_order(), mri_swap2(), mri_swap4(), THD_diskptr::nvals, nz, STORAGE_BY_ANALYZE, THD_diskptr::storage_mode, thd_complexscan(), and thd_floatscan().

Referenced by THD_load_datablock().

00401 {
00402    THD_diskptr *dkptr ;
00403    int nx,ny,nz,nv , nxy,nxyz,nxyzv , ibr,nbad ;
00404    FILE *fp ;
00405    void *ptr ;
00406 
00407 ENTRY("THD_load_analyze") ;
00408 
00409    /*-- check inputs --*/
00410 
00411    if( !ISVALID_DATABLOCK(dblk)                          ||
00412        dblk->diskptr->storage_mode != STORAGE_BY_ANALYZE ||
00413        dblk->brick == NULL                                 ) EXRETURN ;
00414 
00415    dkptr = dblk->diskptr ;
00416 
00417    fp = fopen( dkptr->brick_name , "rb" ) ;  /* .img file */
00418    if( fp == NULL ) EXRETURN ;
00419 
00420    /*-- allocate space for data --*/
00421 
00422    nx = dkptr->dimsizes[0] ;
00423    ny = dkptr->dimsizes[1] ;  nxy   = nx * ny   ;
00424    nz = dkptr->dimsizes[2] ;  nxyz  = nxy * nz  ;
00425    nv = dkptr->nvals       ;  nxyzv = nxyz * nv ;
00426 
00427    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00428 
00429    /*-- malloc space for each brick separately --*/
00430 
00431    for( nbad=ibr=0 ; ibr < nv ; ibr++ ){
00432       if( DBLK_ARRAY(dblk,ibr) == NULL ){
00433          ptr = AFMALL(void, DBLK_BRICK_BYTES(dblk,ibr) ) ;
00434          mri_fix_data_pointer( ptr ,  DBLK_BRICK(dblk,ibr) ) ;
00435          if( ptr == NULL ) nbad++ ;
00436       }
00437    }
00438 
00439    /*-- if couldn't get them all, take our ball and go home in a snit --*/
00440 
00441    if( nbad > 0 ){
00442       fprintf(stderr,
00443               "\n** failed to malloc %d ANALYZE bricks out of %d\n\a",nbad,nv);
00444       for( ibr=0 ; ibr < nv ; ibr++ ){
00445         if( DBLK_ARRAY(dblk,ibr) != NULL ){
00446            free(DBLK_ARRAY(dblk,ibr)) ;
00447            mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,ibr) ) ;
00448         }
00449       }
00450       fclose(fp) ; EXRETURN ;
00451    }
00452 
00453    /*-- read data from .img file into sub-brick arrays! --*/
00454 
00455    for( ibr=0 ; ibr < nv ; ibr++ )
00456      fread( DBLK_ARRAY(dblk,ibr), 1, DBLK_BRICK_BYTES(dblk,ibr), fp ) ;
00457 
00458    fclose(fp) ;
00459 
00460    /*-- swap bytes? --*/
00461 
00462    if( dkptr->byte_order != mri_short_order() ){
00463      for( ibr=0 ; ibr < nv ; ibr++ ){
00464        switch( DBLK_BRICK_TYPE(dblk,ibr) ){
00465          case MRI_short:
00466            mri_swap2( DBLK_BRICK_NVOX(dblk,ibr) , DBLK_ARRAY(dblk,ibr) ) ;
00467          break ;
00468 
00469          case MRI_complex:
00470            mri_swap4( 2*DBLK_BRICK_NVOX(dblk,ibr), DBLK_ARRAY(dblk,ibr)) ;
00471          break ;
00472 
00473          case MRI_float:
00474          case MRI_int:
00475            mri_swap4( DBLK_BRICK_NVOX(dblk,ibr) , DBLK_ARRAY(dblk,ibr) ) ;
00476          break ;
00477        }
00478      }
00479    }
00480 
00481    /*-- check floats --*/
00482 
00483    for( ibr=0 ; ibr < nv ; ibr++ ){
00484      if( DBLK_BRICK_TYPE(dblk,ibr) == MRI_float ){
00485        nbad += thd_floatscan( DBLK_BRICK_NVOX(dblk,ibr) ,
00486                               DBLK_ARRAY(dblk,ibr)        ) ;
00487 
00488      } else if( DBLK_BRICK_TYPE(dblk,ibr) == MRI_complex ) {
00489        nbad += thd_complexscan( DBLK_BRICK_NVOX(dblk,ibr) ,
00490                                 DBLK_ARRAY(dblk,ibr)        ) ;
00491      }
00492    }
00493    if( nbad > 0 )
00494      fprintf(stderr ,
00495              "*** %s: found %d float errors -- see program float_scan\n" ,
00496              dkptr->brick_name , nbad ) ;
00497 
00498    EXRETURN ;
00499 }

void THD_load_ctfmri THD_datablock   dblk
 

Actually load data from a CTF MRI file into a dataset. Adapted from THD_load_analyze(). --------------------------------------------------------------------

Definition at line 514 of file thd_ctfread.c.

References AFMALL, THD_datablock::brick, THD_diskptr::brick_name, THD_diskptr::byte_order, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_NVOX, DBLK_BRICK_TYPE, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_fix_data_pointer(), mri_short_order(), mri_swap2(), THD_diskptr::nvals, nz, STORAGE_BY_CTFMRI, and THD_diskptr::storage_mode.

Referenced by THD_load_datablock().

00515 {
00516    THD_diskptr *dkptr ;
00517    int nx,ny,nz,nv , nxy,nxyz,nxyzv , ibr,nbad ;
00518    FILE *fp ;
00519    void *ptr ;
00520 
00521 ENTRY("THD_load_ctfmri") ;
00522 
00523    /*-- check inputs --*/
00524 
00525    if( !ISVALID_DATABLOCK(dblk)                         ||
00526        dblk->diskptr->storage_mode != STORAGE_BY_CTFMRI ||
00527        dblk->brick == NULL                                ) EXRETURN ;
00528 
00529    dkptr = dblk->diskptr ;
00530 
00531    /* open and position file at start of data (after header) */
00532 
00533    fp = fopen( dkptr->brick_name , "rb" ) ;  /* .mri file */
00534    if( fp == NULL ) EXRETURN ;
00535 
00536    /*-- allocate space for data --*/
00537 
00538    nx = dkptr->dimsizes[0] ;
00539    ny = dkptr->dimsizes[1] ; nxy   = nx * ny   ;
00540    nz = dkptr->dimsizes[2] ; nxyz  = nxy * nz  ;
00541    nv = dkptr->nvals       ; nxyzv = nxyz * nv ;
00542 
00543    /* 26 Feb 2005: seek backwards from end,
00544                    instead of forwards from start */
00545 
00546 #if 0
00547    fseek( fp , sizeof(Version_2_Header) , SEEK_SET ) ;  /* old */
00548 #else
00549    switch( DBLK_BRICK_TYPE(dblk,0) ){
00550      case MRI_float: ibr = sizeof(float) ; break ;   /* illegal */
00551      case MRI_short: ibr = sizeof(short) ; break ;
00552      case MRI_byte:  ibr = sizeof(byte)  ; break ;
00553    }
00554    fseek( fp , -ibr*nxyzv , SEEK_END ) ;                /* new */
00555 #endif
00556 
00557    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00558 
00559    /*-- malloc space for each brick separately --*/
00560 
00561    for( nbad=ibr=0 ; ibr < nv ; ibr++ ){
00562      if( DBLK_ARRAY(dblk,ibr) == NULL ){
00563        ptr = AFMALL(void, DBLK_BRICK_BYTES(dblk,ibr) ) ;
00564        mri_fix_data_pointer( ptr ,  DBLK_BRICK(dblk,ibr) ) ;
00565        if( ptr == NULL ) nbad++ ;
00566      }
00567    }
00568 
00569    /*-- if couldn't get them all, take our ball and go home in a snit --*/
00570 
00571    if( nbad > 0 ){
00572      fprintf(stderr,
00573              "\n** failed to malloc %d CTR MRI bricks out of %d\n\a",nbad,nv);
00574      for( ibr=0 ; ibr < nv ; ibr++ ){
00575        if( DBLK_ARRAY(dblk,ibr) != NULL ){
00576          free(DBLK_ARRAY(dblk,ibr)) ;
00577          mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,ibr) ) ;
00578        }
00579      }
00580      fclose(fp) ; EXRETURN ;
00581    }
00582 
00583 
00584    /*-- read data from .img file into sub-brick arrays! --*/
00585 
00586    for( ibr=0 ; ibr < nv ; ibr++ )
00587      fread( DBLK_ARRAY(dblk,ibr), 1, DBLK_BRICK_BYTES(dblk,ibr), fp ) ;
00588 
00589    fclose(fp) ;
00590 
00591    /*-- swap bytes? --*/
00592 
00593    if( dkptr->byte_order != mri_short_order() ){
00594      for( ibr=0 ; ibr < nv ; ibr++ ){
00595        switch( DBLK_BRICK_TYPE(dblk,ibr) ){
00596          case MRI_short:
00597            mri_swap2( DBLK_BRICK_NVOX(dblk,ibr) , DBLK_ARRAY(dblk,ibr) ) ;
00598          break ;
00599        }
00600      }
00601    }
00602 
00603    EXRETURN ;
00604 }

void THD_load_ctfsam THD_datablock   dblk
 

Actually load data from a CTF SAM file into a dataset. --------------------------------------------------------------------

Definition at line 953 of file thd_ctfread.c.

References AFMALL, THD_datablock::brick, THD_diskptr::brick_name, THD_diskptr::byte_order, calloc, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_fix_data_pointer(), mri_short_order(), THD_diskptr::nvals, nz, STORAGE_BY_CTFSAM, THD_diskptr::storage_mode, swap, and swap_8().

Referenced by THD_load_datablock().

00954 {
00955    THD_diskptr *dkptr ;
00956    int nx,ny,nz,nv , nxy,nxyz,nxyzv , ibr,nbad , ii,swap ;
00957    FILE *fp ;
00958    void *ptr ;
00959    double *dbar ;
00960    float  *ftar ;
00961 
00962 ENTRY("THD_load_ctfsam") ;
00963 
00964    /*-- check inputs --*/
00965 
00966    if( !ISVALID_DATABLOCK(dblk)                         ||
00967        dblk->diskptr->storage_mode != STORAGE_BY_CTFSAM ||
00968        dblk->brick == NULL                                ) EXRETURN ;
00969 
00970    dkptr = dblk->diskptr ;
00971 
00972    /*-- allocate space for data --*/
00973 
00974    nx = dkptr->dimsizes[0] ;
00975    ny = dkptr->dimsizes[1] ; nxy   = nx * ny   ;
00976    nz = dkptr->dimsizes[2] ; nxyz  = nxy * nz  ;
00977    nv = dkptr->nvals       ; nxyzv = nxyz * nv ;
00978 
00979    /* position file 8*nxyzv bytes before end of file */
00980 
00981    fp = fopen( dkptr->brick_name , "rb" ) ;  /* .svl file */
00982    if( fp == NULL ) EXRETURN ;
00983 
00984    /* 26 Feb 2005: instead of skipping the header,
00985                    whose size varies with the SAM version number,
00986                    just seek backwards from the end to the correct size */
00987 
00988    fseek( fp , -sizeof(double)*nxyzv , SEEK_END ) ;
00989 
00990    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00991 
00992    /*-- malloc space for each brick separately --*/
00993 
00994    for( nbad=ibr=0 ; ibr < nv ; ibr++ ){
00995      if( DBLK_ARRAY(dblk,ibr) == NULL ){
00996        ptr = AFMALL(void, DBLK_BRICK_BYTES(dblk,ibr) ) ;
00997        mri_fix_data_pointer( ptr ,  DBLK_BRICK(dblk,ibr) ) ;
00998        if( ptr == NULL ) nbad++ ;
00999      }
01000    }
01001 
01002    /*-- if couldn't get them all, take our ball and go home in a snit --*/
01003 
01004    if( nbad > 0 ){
01005      fprintf(stderr,
01006              "\n** failed to malloc %d CTR MRI bricks out of %d\n\a",nbad,nv);
01007      for( ibr=0 ; ibr < nv ; ibr++ ){
01008        if( DBLK_ARRAY(dblk,ibr) != NULL ){
01009          free(DBLK_ARRAY(dblk,ibr)) ;
01010          mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,ibr) ) ;
01011        }
01012      }
01013      fclose(fp) ; EXRETURN ;
01014    }
01015 
01016    /*-- SAM data is stored as doubles,
01017         but we have to store it in AFNI as floats --*/
01018 
01019    dbar = (double *) calloc(sizeof(double),nxyz) ;     /* workspace */
01020    swap = ( dkptr->byte_order != mri_short_order() ) ;
01021 
01022    for( ibr=0 ; ibr < nv ; ibr++ ){            /* loop over sub-bricks */
01023      fread( dbar, 1, sizeof(double)*nxyz, fp ) ; /* read data to workspace */
01024      ftar = DBLK_ARRAY(dblk,ibr) ;               /* float array in dataset */
01025      for( ii=0 ; ii < nxyz ; ii++ ){             /* loop over voxels */
01026        if( swap ) swap_8(dbar+ii) ;                /* swap it */
01027        ftar[ii] = dbar[ii] ;                       /* save it as a float */
01028      }
01029    }
01030 
01031    fclose(fp) ; free(dbar) ;  /* toss out the trash */
01032    EXRETURN ;
01033 }

Boolean THD_load_datablock THD_datablock  
 

Definition at line 104 of file thd_loaddblk.c.

References AFMALL, AFNI_yesenv(), THD_datablock::brick, THD_diskptr::brick_name, THD_diskptr::byte_order, BYTEIZE, ATR_string::ch, close(), COMPRESS_fclose(), COMPRESS_fopen_read(), CSQR, DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DATABLOCK_MEM_SHARED, DATABLOCK_MEM_UNDEFINED, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_FACTOR, DBLK_BRICK_NVOX, DBLK_BRICK_TYPE, DBLK_IS_MASTERED, DBLK_mmapfix, THD_diskptr::dimsizes, THD_diskptr::directory_name, THD_datablock::diskptr, DSET_BRIKNAME, DSET_IS_TCAT, ENTRY, far, fd, THD_diskptr::filecode, floatscan, free, freeup, getenv(), complex::i, ISVALID_DATABLOCK, ISVALID_DISKPTR, ISVALID_DSET, malloc, THD_datablock::malloc_type, THD_datablock::master_bot, THD_datablock::master_bytes, THD_datablock::master_ival, THD_datablock::master_nvals, THD_datablock::master_top, mri_clear_data_pointer, mri_fix_data_pointer(), mri_short_order(), mri_swap2(), mri_swap4(), native_order, ATR_string::nch, no_mmap, THD_datablock::nvals, THD_diskptr::nvals, nz, offset, THD_datablock::parent, PRINT_SIZE, PRINT_STEP, complex::r, THD_diskptr::rank, RETURN, SHORTIZE, STATUS, STORAGE_BY_1D, STORAGE_BY_3D, STORAGE_BY_ANALYZE, STORAGE_BY_BRICK, STORAGE_BY_CTFMRI, STORAGE_BY_CTFSAM, STORAGE_BY_MINC, STORAGE_BY_MPEG, STORAGE_BY_NIFTI, STORAGE_BY_VOLUMES, THD_diskptr::storage_mode, STORAGE_UNDEFINED, THD_alloc_datablock(), thd_complexscan(), THD_count_databricks(), THD_datum_constant(), THD_filesize(), THD_find_string_atr(), thd_floatscan(), THD_load_1D(), THD_load_3D(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_minc(), THD_load_mpeg(), THD_load_nifti(), THD_load_tcat(), THD_MMAP_FLAG, THD_purge_datablock(), THD_update_statistics(), top, THD_datablock::total_bytes, and verbose.

Referenced by AFNI_dataset_slice(), AFNI_fimmer_compute(), CALC_read_opts(), copy_dset(), DSET_cor(), EDIT_full_copy(), EDIT_one_dataset(), FD_brick_to_mri(), FD_brick_to_series(), fim3d_fimmer_compute(), get_options(), main(), read_input_data(), and THD_extract_many_series().

00105 {
00106    THD_diskptr *dkptr ;
00107    int id , offset ;
00108    int nx,ny,nz , nxy,nxyz , nv,vv , ii , ibr , nbad ;
00109    char *ptr ;
00110    MRI_IMAGE *im ;
00111    int verb=verbose ;
00112    int64_t idone , print_size=PRINT_SIZE ;
00113 
00114 ENTRY("THD_load_datablock") ; /* 29 Aug 2001 */
00115 
00116    if( native_order < 0 ) native_order = mri_short_order() ; /* 1st time in */
00117 
00118    floatscan = AFNI_yesenv("AFNI_FLOATSCAN") ;  /* check float bricks? */
00119 
00120    if( floatscan ) no_mmap = 1 ;                          /* perhaps disable */
00121    else            no_mmap = AFNI_yesenv("AFNI_NOMMAP") ; /* use of mmap()  */
00122 
00123    /*-- sanity checks --*/
00124 
00125    if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ){
00126      STATUS("Illegal inputs"); RETURN( False );
00127    }
00128 
00129    ii = THD_count_databricks( blk ) ;
00130    if( ii == blk->nvals ) RETURN( True );   /* already loaded! */
00131 
00132    if( blk->malloc_type == DATABLOCK_MEM_UNDEFINED ){
00133      STATUS("malloc_type forced to DATABLOCK_MEM_MALLOC") ;
00134      blk->malloc_type = DATABLOCK_MEM_MALLOC ;
00135    }
00136 
00137    /* these next 2 conditions should never happen */
00138 
00139    dkptr = blk->diskptr ;
00140    if( ! ISVALID_DISKPTR(dkptr) ){
00141      STATUS("invalid dkptr!!!"); RETURN( False );
00142    }
00143    if( dkptr->storage_mode == STORAGE_UNDEFINED ){
00144      if( PRINT_TRACING ){
00145        char str[512] ; THD_3dim_dataset *dset=(THD_3dim_dataset *)(blk->parent) ;
00146        sprintf(str,"dataset %s == STORAGE_UNDEFINED",DSET_BRIKNAME(dset)) ;
00147        STATUS(str) ;
00148      }
00149      RETURN(False) ;
00150    }
00151 
00152    if( dkptr->rank != 3 ){
00153      fprintf(stderr,"\n*** Cannot read non 3D datablocks ***\n"); RETURN(False);
00154    }
00155 
00156    if( dkptr->storage_mode == STORAGE_BY_VOLUMES ) no_mmap = 1 ;  /* 20 Jun 2002 */
00157 
00158    /*-- 29 Oct 2001: MINC input (etc.) --*/
00159 
00160    if( dkptr->storage_mode == STORAGE_BY_MINC ){
00161      THD_load_minc( blk ) ;
00162      ii = THD_count_databricks( blk ) ;
00163      if( ii == blk->nvals ){
00164        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00165        RETURN( True ) ;
00166      }
00167      STATUS("can't read MINC file?!") ;
00168      RETURN( False ) ;
00169    }
00170 
00171    { THD_3dim_dataset *ds = (THD_3dim_dataset *)blk->parent ;  /* 04 Aug 2004 */
00172      if( ISVALID_DSET(ds) && DSET_IS_TCAT(ds) ){
00173        THD_load_tcat( blk ) ;
00174        ii = THD_count_databricks( blk ) ;
00175        if( ii == blk->nvals ){
00176          THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00177          RETURN( True ) ;
00178        }
00179        STATUS("can't read tcat-ed file?!") ;
00180        RETURN( False ) ;
00181      }
00182    }
00183 
00184    if( dkptr->storage_mode == STORAGE_BY_ANALYZE ){
00185      THD_load_analyze( blk ) ;
00186      ii = THD_count_databricks( blk ) ;
00187      if( ii == blk->nvals ){
00188        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00189        RETURN( True ) ;
00190      }
00191      STATUS("can't read ANALYZE file?!") ;
00192      RETURN( False ) ;
00193    }
00194 
00195    if( dkptr->storage_mode == STORAGE_BY_CTFMRI ){  /* 04 Dec 2002 */
00196      THD_load_ctfmri( blk ) ;
00197      ii = THD_count_databricks( blk ) ;
00198      if( ii == blk->nvals ){
00199        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00200        RETURN( True ) ;
00201      }
00202      STATUS("can't read CTF MRI file?!") ;
00203      RETURN( False ) ;
00204    }
00205 
00206    if( dkptr->storage_mode == STORAGE_BY_CTFSAM ){  /* 04 Dec 2002 */
00207      THD_load_ctfsam( blk ) ;
00208      ii = THD_count_databricks( blk ) ;
00209      if( ii == blk->nvals ){
00210        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00211        RETURN( True ) ;
00212      }
00213      STATUS("can't read CTF SAM file?!") ;
00214      RETURN( False ) ;
00215    }
00216 
00217    if( dkptr->storage_mode == STORAGE_BY_1D ){      /* 04 Mar 2003 */
00218      THD_load_1D( blk ) ;
00219      ii = THD_count_databricks( blk ) ;
00220      if( ii == blk->nvals ){
00221        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00222        RETURN( True ) ;
00223      }
00224      STATUS("can't read 1D dataset file?!") ;
00225      RETURN( False ) ;
00226    }
00227 
00228    if( dkptr->storage_mode == STORAGE_BY_3D ){      /* 21 Mar 2003 */
00229      THD_load_3D( blk ) ;
00230      ii = THD_count_databricks( blk ) ;
00231      if( ii == blk->nvals ){
00232        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00233        RETURN( True ) ;
00234      }
00235      STATUS("can't read 3D dataset file?!") ;
00236      RETURN( False ) ;
00237    }
00238 
00239    if( dkptr->storage_mode == STORAGE_BY_NIFTI ){   /* 28 Aug 2003 */
00240      THD_load_nifti( blk ) ;
00241      ii = THD_count_databricks( blk ) ;
00242      if( ii == blk->nvals ){
00243        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00244        RETURN( True ) ;
00245      }
00246      STATUS("can't read NIFTI dataset file?!") ;
00247      RETURN( False ) ;
00248    }
00249 
00250    if( dkptr->storage_mode == STORAGE_BY_MPEG ){   /* 03 Dec 2003 */
00251      THD_load_mpeg( blk ) ;
00252      ii = THD_count_databricks( blk ) ;
00253      if( ii == blk->nvals ){
00254        THD_update_statistics( (THD_3dim_dataset *)blk->parent ) ;
00255        RETURN( True ) ;
00256      }
00257      STATUS("can't read MPEG dataset file?!") ;
00258      RETURN( False ) ;
00259    }
00260 
00261    /*** END OF SPECIAL CASES ABOVE; NOW FOR THE AFNI FORMAT! ***/
00262 
00263    /*-- allocate data space --*/
00264 
00265    nx = dkptr->dimsizes[0] ;
00266    ny = dkptr->dimsizes[1] ;  nxy   = nx * ny   ;
00267    nz = dkptr->dimsizes[2] ;  nxyz  = nxy * nz  ;
00268    nv = dkptr->nvals       ;
00269 
00270    if( DBLK_IS_MASTERED(blk) && blk->malloc_type == DATABLOCK_MEM_MMAP ) /* 11 Jan 1999 */
00271       blk->malloc_type = DATABLOCK_MEM_MALLOC ;
00272 
00273    /* the following code is due to Mike Beauchamp's idiocy */
00274 
00275    if( !THD_datum_constant(blk) && blk->malloc_type != DATABLOCK_MEM_MALLOC ){
00276      fprintf(stderr,"++ WARNING: dataset %s: non-uniform sub-brick types\n",
00277              blk->diskptr->filecode) ;
00278      blk->malloc_type = DATABLOCK_MEM_MALLOC ;
00279    }
00280 
00281    /* 25 April 1998: byte order issues */
00282 
00283    if( dkptr->byte_order <= 0 ) dkptr->byte_order = native_order ;
00284 
00285    /* 05 Jul 2001: if all sub-bricks are bytes,
00286                    mark dataset as being in native order
00287       20 Jun 2002: also don't have to swap RGB datasets */
00288 
00289    if( dkptr->byte_order != native_order ){
00290       for( ii=0 ; ii < nv ; ii++ )
00291          if( DBLK_BRICK_TYPE(blk,ii) != MRI_byte &&
00292              DBLK_BRICK_TYPE(blk,ii) != MRI_rgb     ) break ;
00293       if( ii == nv ) dkptr->byte_order = native_order ;
00294    }
00295 
00296    /* under some circumstances, we must force use of malloc() */
00297 
00298    if( dkptr->byte_order != native_order || no_mmap ){
00299      if( blk->malloc_type == DATABLOCK_MEM_MMAP )
00300        blk->malloc_type = DATABLOCK_MEM_MALLOC ;
00301    }
00302 
00303    DBLK_mmapfix(blk) ;  /* 18 Mar 2005 */
00304 
00305    /** set up space for bricks via malloc, if so ordered **/
00306 
00307    if( blk->malloc_type == DATABLOCK_MEM_MALLOC ||
00308        blk->malloc_type == DATABLOCK_MEM_SHARED   ){
00309 
00310      ii = THD_alloc_datablock( blk ) ;   /* 02 May 2003 */
00311      if( ii == 0 ) RETURN(False) ;
00312 
00313    /** mmap whole file (makes space and reads it all at once) **/
00314    /** [if this route is followed, then we will finish here]  **/
00315 
00316    } else if( blk->malloc_type == DATABLOCK_MEM_MMAP ){
00317 
00318       int fd , fsize ;
00319       fd = open( dkptr->brick_name , O_RDONLY ) ;  /* N.B.: readonly mode */
00320       if( fd < 0 ){
00321          fprintf( stderr , "\n*** cannot open brick file %s for mmap\n"
00322                            "   - do you have permission? does file exist?\n" ,
00323                   dkptr->brick_name ) ;
00324          perror("*** Unix error message") ;
00325          STATUS("open failed") ;
00326          RETURN( False );
00327       }
00328 
00329       /* 04 May 2001: check file size (the Katie Lee bug) */
00330 
00331       fsize = THD_filesize( dkptr->brick_name ) ;
00332       if( fsize < blk->total_bytes )
00333         fprintf(stderr ,
00334                 "\n*** WARNING: file %s size is %d, but should be at least %lld!\n" ,
00335                 dkptr->brick_name , fsize , blk->total_bytes ) ;
00336 
00337       /* clear the sub-brick pointers */
00338 
00339       for( ibr=0 ; ibr < nv ; ibr++ )
00340         mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00341 
00342       /* map the file into memory */
00343 
00344       ptr = (char *) mmap( 0 , (size_t)blk->total_bytes ,
00345                                PROT_READ , THD_MMAP_FLAG , fd , 0 ) ;
00346 
00347       /* if that fails, maybe try again (via freeup) */
00348 
00349       if( ptr == (char *)(-1) ){
00350          fprintf(stderr ,
00351                  "\n*** cannot mmap brick file %s - maybe hit a system limit?\n" ,
00352                  dkptr->brick_name ) ;
00353          perror("*** Unix error message") ;
00354          if( freeup != NULL ){
00355             fprintf(stderr,"*** trying to fix problem\n") ; /* 18 Oct 2001 */
00356             freeup() ;                          /* AFNI_purge_unused_dsets */
00357             ptr = (char *) mmap( 0 , (size_t)blk->total_bytes ,
00358                                      PROT_READ , THD_MMAP_FLAG , fd , 0 ) ;
00359             if( ptr == (char *)(-1) ){
00360                fprintf(stderr,"*** cannot fix problem!\n") ;
00361                close(fd) ;
00362                STATUS("freeup failed") ; RETURN( False );
00363             } else {
00364                fprintf(stderr,"*** was able to fix problem!\n") ;
00365             }
00366          } else {       /* no freeup function to try */
00367             close(fd) ;
00368             STATUS("mmap failed") ; RETURN( False );
00369          }
00370       }
00371 
00372       close(fd) ;  /* can close file after mmap-ing it */
00373 
00374       /* (re)create pointers to all sub-bricks */
00375 
00376       offset = 0 ;
00377       for( ibr=0 ; ibr < nv ; ibr++ ){
00378          mri_fix_data_pointer( ptr , DBLK_BRICK(blk,ibr) ) ;
00379          ptr += DBLK_BRICK_BYTES(blk,ibr) ;
00380       }
00381 
00382       STATUS("mmap succeeded") ;
00383       RETURN( True );  /* finito */
00384 
00385    } else {
00386       STATUS("unknown malloc_type code?!") ;
00387       RETURN( False ) ;  /* should never happen */
00388    }
00389 
00390    /*** Below here, space for brick images was malloc()-ed,
00391         and now we have to read data into them, somehow    ***/
00392 
00393    ptr = getenv("AFNI_LOAD_PRINTSIZE") ;   /* 23 Aug 2002 */
00394    if( verb && ptr != NULL ){
00395      char *ept ;
00396      idone = strtol( ptr , &ept , 10 ) ;
00397      if( idone > 0 ){
00398             if( *ept == 'K' || *ept == 'k' ) id *= 1024 ;
00399        else if( *ept == 'M' || *ept == 'm' ) id *= 1024*1024 ;
00400        print_size = id ;
00401      } else {
00402        print_size = 666000000 ;
00403      }
00404    }
00405 
00406    if( verb ) verb = (blk->total_bytes > print_size) ;
00407    if( verb ) fprintf(stderr,"reading dataset %s",dkptr->filecode) ;
00408 
00409    switch( dkptr->storage_mode ){
00410 
00411       /*-- should never ever happen --*/
00412 
00413       default:
00414          fprintf(stderr,"\n*** illegal storage mode in read ***\n") ;
00415          RETURN( False );
00416       break ;
00417 
00418       /*-- read everything from .BRIK file --*/
00419 
00420       case STORAGE_BY_BRICK:{
00421          FILE *far ;
00422 
00423          STATUS("reading from BRIK file") ;
00424 
00425          far = COMPRESS_fopen_read( dkptr->brick_name ) ;
00426 
00427          if( far == NULL ){
00428             THD_purge_datablock( blk , blk->malloc_type ) ;
00429             fprintf(stderr,
00430                     "\n*** failure while opening brick file %s "
00431                     "- do you have permission?\n" ,
00432                     dkptr->brick_name ) ;
00433             perror("*** Unix error message") ;
00434             RETURN( False );
00435          }
00436 
00437          /* read each sub-brick all at once */
00438 
00439          idone = 0 ;
00440          if( ! DBLK_IS_MASTERED(blk) ){      /* read each brick */
00441 
00442             for( ibr=0 ; ibr < nv ; ibr++ ){
00443               idone += fread( DBLK_ARRAY(blk,ibr), 1,
00444                               DBLK_BRICK_BYTES(blk,ibr), far ) ;
00445 
00446               if( verb && ibr%PRINT_STEP == 0 ) fprintf(stderr,".") ;
00447             }
00448 
00449          } else {  /* 11 Jan 1999: read brick from master, put into place(s) */
00450 
00451             int nfilled = 0 , nbuf=0 , jbr, nbr ;
00452             char *buf=NULL ;  /* temp buffer for master sub-brick */
00453 
00454             /* loop over master sub-bricks until dataset is filled */
00455             /* [because dataset might be compressed, must read them in
00456                 sequence, even if some intermediate ones aren't used. ] */
00457 
00458             for( ibr=0 ; nfilled < nv && ibr < blk->master_nvals ; ibr++ ){
00459 
00460                if( nbuf < blk->master_bytes[ibr] ){  /* make more space for it */
00461                  if( buf != NULL ) free(buf) ;
00462                  nbuf = blk->master_bytes[ibr] ;
00463                  buf  = AFMALL(char, sizeof(char) * nbuf ) ;
00464                  if( buf == NULL ) break ;
00465                }
00466 
00467                /* read the master sub-brick #ibr */
00468 
00469                nbr = fread( buf , 1 , blk->master_bytes[ibr] , far ) ;
00470                if( verb && ibr%PRINT_STEP == 0 ) fprintf(stderr,".") ;
00471                if( nbr < blk->master_bytes[ibr] ) break ;
00472 
00473                /* find all the dataset sub-bricks that are copies of this */
00474 
00475                for( jbr=0 ; jbr < nv ; jbr++ ){
00476                  if( blk->master_ival[jbr] == ibr ){  /* copy it in */
00477                    memcpy( DBLK_ARRAY(blk,jbr) , buf , blk->master_bytes[ibr] ) ;
00478                    nfilled++ ;  /* number of bricks filled */
00479                    idone += nbr ;  /* number of bytes read into dataset */
00480                  }
00481                }
00482             }  /* end of loop over master sub-bricks */
00483 
00484             if( buf != NULL ) free(buf) ;  /* free temp sub-brick */
00485          }
00486 
00487          /* close input file */
00488 
00489          COMPRESS_fclose(far) ;
00490 
00491          /* check if total amount of data read is correct */
00492 
00493          if( idone != blk->total_bytes ){
00494             THD_purge_datablock( blk , blk->malloc_type ) ;
00495             fprintf(stderr ,
00496                     "\n*** failure while reading from brick file %s\n"
00497                       "*** desired %lld bytes but only got %lld\n" ,
00498                     dkptr->brick_name , blk->total_bytes , idone ) ;
00499             perror("*** Unix error message") ;
00500             RETURN( False );
00501          }
00502       }
00503       break ;  /* end of STORAGE_BY_BRICK */
00504 
00505       /*** Read from a sequence of volume files (1 per sub-brick) [20 Jun 2002] ***/
00506 
00507       case STORAGE_BY_VOLUMES:{
00508         ATR_string *atr ;
00509         char **fnam , *ptr , *flist ;
00510         FILE *far ;
00511 
00512         STATUS("reading from volume files") ;
00513 
00514         /* get list of filenames */
00515 
00516         atr = THD_find_string_atr(blk,"VOLUME_FILENAMES") ;
00517 
00518         /* the following should never happen */
00519 
00520         if( atr == NULL || atr->nch < 2*nv ){
00521           THD_purge_datablock( blk , blk->malloc_type ) ;
00522           fprintf(stderr,
00523                   "Dataset %s does not have legal VOLUME_FILENAMES attribute!\n",
00524                   blk->diskptr->filecode) ;
00525           RETURN( False );
00526         }
00527 
00528         /* copy filename list into NUL terminated local string */
00529 
00530         flist = AFMALL(char, atr->nch+1) ;
00531         memcpy( flist , atr->ch , atr->nch ) ;
00532         flist[atr->nch] = '\0' ;
00533 
00534 #if 0
00535 fprintf(stderr,"VOL: flist:\n%s\n",flist) ;
00536 #endif
00537 
00538         /* break filename list into component filenames (1 per sub-brick) */
00539 
00540         fnam = (char **) malloc(sizeof(char *)*nv) ;
00541         for( ibr=0 ; ibr < nv ; ibr++ ){
00542 
00543           /* find sub-string with next filename */
00544 
00545           ptr = strtok( (ibr==0)?flist:NULL , " \t\n\r\f\v" ) ;
00546 
00547           /* didn't get one => bad news */
00548 
00549           if( ptr == NULL ){
00550             fprintf(stderr,
00551                     "Dataset %s has illegal VOLUME_FILENAMES attribute!\n",
00552                     blk->diskptr->filecode) ;
00553             for( ii=0 ; ii < nv ; ii++ ){
00554               free( DBLK_ARRAY(blk,ii) ) ;
00555               mri_clear_data_pointer( DBLK_BRICK(blk,ii) ) ;
00556             }
00557             for( ii=0 ; ii < ibr ; ii++ ) free(fnam[ii]) ;
00558             free(flist) ; free(fnam) ;
00559             RETURN( False );
00560           }
00561 
00562           /* make fnam[ibr] = name ibr-th volume file */
00563 
00564 #if 0
00565 fprintf(stderr,"VOL[%d]: ptr=%s\n",ibr,ptr) ;
00566 #endif
00567 
00568           if( *ptr == '/' ){          /* if filename is absolute, duplicate it */
00569             fnam[ibr] = strdup(ptr) ;
00570           } else {                    /* otherwise, put directory name in front */
00571             ii = strlen(blk->diskptr->directory_name) + strlen(ptr) ;
00572             fnam[ibr] = AFMALL(char,ii+1) ; fnam[ibr][0] = '\0' ;
00573             strcat(fnam[ibr],blk->diskptr->directory_name) ;
00574             strcat(fnam[ibr],ptr) ;
00575           }
00576 #if 0
00577 fprintf(stderr,"VOL[%d]: fnam=%s\n",ibr,fnam[ibr]) ;
00578 #endif
00579         }
00580         free(flist) ;  /* done with unparsed filename list copy */
00581 
00582         /*** loop over sub-bricks and read them in ***/
00583 
00584         if( ! DBLK_IS_MASTERED(blk) ){      /* read each brick */
00585 
00586           for( ibr=0 ; ibr < nv ; ibr++ ){
00587 
00588 #if 0
00589 fprintf(stderr,"VOL[%d]: opening %s\n",ibr,fnam[ibr]) ;
00590 #endif
00591 
00592             far = COMPRESS_fopen_read( fnam[ibr] ) ;  /* open file */
00593 
00594             if( far == NULL ){                   /* can't open it? */
00595               fprintf(stderr,
00596                       "\n*** Failure while opening volume file %s "
00597                       "- do you have permission?\n" ,
00598                     fnam[ibr] ) ;
00599               perror("*** Unix error message") ;
00600               THD_purge_datablock( blk , blk->malloc_type ) ;
00601               for( ii=0 ; ii < nv ; ii++ ) free(fnam[ii]) ;
00602               free(fnam); RETURN( False );
00603             }
00604 
00605             /* read all of file at once */
00606 
00607             id = fread( DBLK_ARRAY(blk,ibr), 1,
00608                         DBLK_BRICK_BYTES(blk,ibr), far ) ;
00609             if( verb && ibr%PRINT_STEP==0 ) fprintf(stderr,".") ;
00610 
00611 #if 0
00612 fprintf(stderr,"VOL[%d]: id=%d\n",ibr,id) ;
00613 #endif
00614 
00615             COMPRESS_fclose(far) ;
00616 
00617             if( id < DBLK_BRICK_BYTES(blk,ibr) ){
00618               fprintf(stderr,
00619                       "\n*** Volume file %s only gave %d out of %d bytes needed!\n",
00620                      fnam[ibr] , id , DBLK_BRICK_BYTES(blk,ibr) ) ;
00621               THD_purge_datablock( blk , blk->malloc_type ) ;
00622               for( ii=0 ; ii < nv ; ii++ ) free(fnam[ii]) ;
00623               free(fnam); RETURN( False );
00624             }
00625 
00626           } /* end of loop over sub-bricks */
00627 
00628         } else {  /*** Mastered dataset ==> must read only selected sub-bricks ***/
00629 
00630           int jbr ;
00631 
00632           /** loop over output sub-bricks **/
00633 
00634           for( jbr=0 ; jbr < nv ; jbr++ ){
00635             ibr = blk->master_ival[jbr] ;             /* master sub-brick index */
00636             far = COMPRESS_fopen_read( fnam[ibr] ) ;  /* open file */
00637 
00638             if( far == NULL ){                   /* can't open it? */
00639               fprintf(stderr,
00640                       "\n*** Failure while opening volume file %s "
00641                       "- do you have permission?\n" ,
00642                     fnam[ibr] ) ;
00643               perror("*** Unix error message") ;
00644               THD_purge_datablock( blk , blk->malloc_type ) ;
00645               for( ii=0 ; ii < nv ; ii++ ) free(fnam[ii]) ;
00646               free(fnam); RETURN( False );
00647             }
00648 
00649             /* read all of file at once */
00650 
00651             id = fread( DBLK_ARRAY(blk,jbr), 1,
00652                         DBLK_BRICK_BYTES(blk,jbr), far ) ;
00653             if( verb && jbr%PRINT_STEP == 0 ) fprintf(stderr,".") ;
00654 
00655             COMPRESS_fclose(far) ;
00656 
00657             if( id < DBLK_BRICK_BYTES(blk,jbr) ){
00658               fprintf(stderr,
00659                       "\n*** Volume file %s only gave %d out of %d bytes needed!\n",
00660                      fnam[ibr] , id , DBLK_BRICK_BYTES(blk,jbr) ) ;
00661               THD_purge_datablock( blk , blk->malloc_type ) ;
00662               for( ii=0 ; ii < nv ; ii++ ) free(fnam[ii]) ;
00663               free(fnam); RETURN( False );
00664             }
00665 
00666           } /* end of loop over sub-bricks */
00667 
00668         } /* end of mastered vs. unmastered dataset */
00669 
00670         /*** at this point, all the data has been read in ***/
00671 
00672         /* volume filenames no longer needed */
00673 
00674         for( ii=0 ; ii < nv ; ii++ ) free(fnam[ii]) ;
00675         free(fnam) ;
00676 
00677       }
00678       break ; /* end of STORAGE_BY_VOLUMES */
00679 
00680    } /* end of switch on storage modes */
00681 
00682    /************* At this point, data is all in bricks;
00683                   now do any post-processing before exiting *************/
00684 
00685    STATUS("data has been read in") ;
00686 
00687    /* 25 April 1998: check and fix byte ordering */
00688 
00689    if( dkptr->byte_order != native_order ){
00690       STATUS("byte swapping") ;
00691       if( verb ) fprintf(stderr,".byte swap") ;
00692 
00693       for( ibr=0 ; ibr < nv ; ibr++ ){
00694          switch( DBLK_BRICK_TYPE(blk,ibr) ){
00695             case MRI_short:
00696                mri_swap2( DBLK_BRICK_NVOX(blk,ibr) , DBLK_ARRAY(blk,ibr) ) ;
00697             break ;
00698 
00699             case MRI_complex:  /* 14 Sep 1999: swap complex also! */
00700                mri_swap4( 2*DBLK_BRICK_NVOX(blk,ibr), DBLK_ARRAY(blk,ibr)) ;
00701             break ;
00702 
00703             case MRI_float:
00704             case MRI_int:
00705                mri_swap4( DBLK_BRICK_NVOX(blk,ibr) , DBLK_ARRAY(blk,ibr) ) ;
00706             break ;
00707          }
00708       }
00709    }
00710 
00711    /* 30 July 1999: check float sub-brick for errors? */
00712    /* 14 Sep  1999: also check complex sub-bricks!    */
00713 
00714    if( floatscan ){
00715       int nerr=0 ;
00716       STATUS("float scanning") ;
00717       if( verb ) fprintf(stderr,".float scan") ;
00718 
00719       for( ibr=0 ; ibr < nv ; ibr++ ){
00720          if( DBLK_BRICK_TYPE(blk,ibr) == MRI_float ){
00721             nerr += thd_floatscan( DBLK_BRICK_NVOX(blk,ibr) ,
00722                                    DBLK_ARRAY(blk,ibr)        ) ;
00723 
00724          } else if( DBLK_BRICK_TYPE(blk,ibr) == MRI_complex ) {  /* 14 Sep 1999 */
00725             nerr += thd_complexscan( DBLK_BRICK_NVOX(blk,ibr) ,
00726                                      DBLK_ARRAY(blk,ibr)        ) ;
00727          }
00728       }
00729       if( nerr > 0 )
00730          fprintf(stderr ,
00731                  "*** %s: found %d float errors -- see program float_scan\n" ,
00732                  dkptr->brick_name , nerr ) ;
00733    }
00734 
00735    /* 21 Feb 2001: if sub-ranging also used, clip values in brick */
00736 
00737 #if 0
00738 fprintf(stderr,"master_bot=%g master_top=%g\n",blk->master_bot,blk->master_top) ;
00739 #endif
00740    if( DBLK_IS_MASTERED(blk) && blk->master_bot <= blk->master_top ){
00741       float bot = blk->master_bot , top = blk->master_top , fac ;
00742       int jbr ;
00743 
00744       STATUS("sub-ranging") ;
00745       if( verb ) fprintf(stderr,".sub-range") ;
00746 
00747       for( jbr=0 ; jbr < nv ; jbr++ ){
00748          switch( DBLK_BRICK_TYPE(blk,jbr) ){
00749 
00750             default:
00751                fprintf(stderr,
00752                        "** Can't sub-range datum type %s!\n",
00753                        MRI_TYPE_name[DBLK_BRICK_TYPE(blk,jbr)]) ;
00754             break ;
00755 
00756             case MRI_short:{
00757                short mbot, mtop, *mar = (short *) DBLK_ARRAY(blk,jbr) ;
00758                float mfac = DBLK_BRICK_FACTOR(blk,jbr) ;
00759                if( mfac == 0.0 ) mfac = 1.0 ;
00760                mbot = SHORTIZE(bot/mfac) ; mtop = SHORTIZE(top/mfac) ;
00761 #if 0
00762 fprintf(stderr,"mbot=%d mtop=%d\n",(int)mbot,(int)mtop) ;
00763 #endif
00764                for( ii=0 ; ii < nxyz ; ii++ )
00765                   if( mar[ii] < mbot || mar[ii] > mtop ) mar[ii] = 0 ;
00766             }
00767             break ;
00768 
00769             case MRI_int:{
00770                int mbot, mtop, *mar = (int *) DBLK_ARRAY(blk,jbr) ;
00771                float mfac = DBLK_BRICK_FACTOR(blk,jbr) ;
00772                if( mfac == 0.0 ) mfac = 1.0 ;
00773                mbot = rint(bot/mfac) ; mtop = rint(top/mfac) ;
00774                for( ii=0 ; ii < nxyz ; ii++ )
00775                   if( mar[ii] < mbot || mar[ii] > mtop ) mar[ii] = 0 ;
00776             }
00777             break ;
00778 
00779             case MRI_byte:{
00780                byte mbot, mtop, *mar = (byte *) DBLK_ARRAY(blk,jbr) ;
00781                float mfac = DBLK_BRICK_FACTOR(blk,jbr) ;
00782                if( mfac == 0.0 ) mfac = 1.0 ;
00783                mbot = BYTEIZE(bot/mfac) ; mtop = BYTEIZE(top/mfac) ;
00784                for( ii=0 ; ii < nxyz ; ii++ )
00785                   if( mar[ii] < mbot || mar[ii] > mtop ) mar[ii] = 0 ;
00786             }
00787             break ;
00788 
00789             case MRI_float:{
00790                float mbot, mtop, *mar = (float *) DBLK_ARRAY(blk,jbr) ;
00791                float mfac = DBLK_BRICK_FACTOR(blk,jbr) ;
00792                if( mfac == 0.0 ) mfac = 1.0 ;
00793                mbot = (bot/mfac) ; mtop = (top/mfac) ;
00794                for( ii=0 ; ii < nxyz ; ii++ )
00795                   if( mar[ii] < mbot || mar[ii] > mtop ) mar[ii] = 0 ;
00796             }
00797             break ;
00798 
00799             case MRI_complex:{
00800                float mbot, mtop , val ;
00801                complex *mar = (complex *) DBLK_ARRAY(blk,jbr) ;
00802                float mfac = DBLK_BRICK_FACTOR(blk,jbr) ;
00803                if( mfac == 0.0 ) mfac = 1.0 ;
00804                mbot = (bot/mfac) ; mtop = (top/mfac) ;
00805                mbot = (mbot > 0) ? mbot*mbot : 0 ;
00806                mtop = (mtop > 0) ? mtop*mtop : 0 ;
00807                for( ii=0 ; ii < nxyz ; ii++ ){
00808                   val = CSQR(mar[ii]) ;
00809                   if( val < mbot || val > mtop ) mar[ii].r = mar[ii].i = 0 ;
00810                }
00811             }
00812             break ;
00813          }
00814       }
00815    }
00816 
00817    if( verb ) fprintf(stderr,".done\n") ;
00818 
00819    RETURN( True ) ;  /* things are now cool */
00820 }

void THD_load_datablock_verbose int   
 

Definition at line 19 of file thd_loaddblk.c.

References v, and verbose.

Referenced by main().

00019 { verbose = v; }

void THD_load_minc THD_datablock  
 

Definition at line 350 of file thd_mincread.c.

References AFMALL, AFNI_noenv(), THD_datablock::brick, THD_diskptr::brick_name, calloc, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_TYPE, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, EPR, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, MAX, mri_fix_data_pointer(), MRI_IS_INT_TYPE, nc_close(), nc_get_att_float(), nc_get_var_float(), nc_get_var_short(), nc_get_var_uchar(), nc_get_vara_float(), nc_get_vara_short(), nc_get_vara_uchar(), nc_inq_varid(), nc_inq_vartype(), nc_open(), THD_diskptr::nvals, nz, STORAGE_BY_MINC, and THD_diskptr::storage_mode.

Referenced by THD_load_datablock().

00351 {
00352    THD_diskptr *dkptr ;
00353    int im_varid , code , ncid ;
00354    int nx,ny,nz,nxy,nxyz,nxyzv , nbad,ibr,nv, nslice ;
00355    void *ptr ;
00356    nc_type im_type=NC_SHORT ;
00357    float im_valid_range[2], fac,denom , intop,inbot , outbot,outtop , sfac=1.0;
00358    float *im_min=NULL  , *im_max=NULL  ;
00359    int    im_min_varid ,  im_max_varid , do_scale ;
00360 
00361 ENTRY("THD_load_minc") ;
00362 
00363    /*-- open input [these errors should never occur] --*/
00364 
00365    if( !ISVALID_DATABLOCK(dblk)                       ||
00366        dblk->diskptr->storage_mode != STORAGE_BY_MINC ||
00367        dblk->brick == NULL                              ) EXRETURN ;
00368 
00369    dkptr = dblk->diskptr ;
00370 
00371    code = nc_open( dkptr->brick_name , NC_NOWRITE , &ncid ) ;
00372    if( code != NC_NOERR ){ EPR(code,dkptr->brick_name,"open"); EXRETURN; }
00373 
00374    code = nc_inq_varid( ncid , "image" , &im_varid ) ;
00375    if( code != NC_NOERR ){ EPR(code,dkptr->brick_name,"image varid"); nc_close(ncid); EXRETURN; }
00376 
00377    /*-- allocate space for data --*/
00378 
00379    nx = dkptr->dimsizes[0] ;
00380    ny = dkptr->dimsizes[1] ;  nxy   = nx * ny   ;
00381    nz = dkptr->dimsizes[2] ;  nxyz  = nxy * nz  ;
00382    nv = dkptr->nvals       ;  nxyzv = nxyz * nv ; nslice = nz*nv ;
00383 
00384    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00385 
00386    /** malloc space for each brick separately **/
00387 
00388    for( nbad=ibr=0 ; ibr < nv ; ibr++ ){
00389       if( DBLK_ARRAY(dblk,ibr) == NULL ){
00390          ptr = AFMALL(void, DBLK_BRICK_BYTES(dblk,ibr) ) ;
00391          mri_fix_data_pointer( ptr ,  DBLK_BRICK(dblk,ibr) ) ;
00392          if( ptr == NULL ) nbad++ ;
00393       }
00394    }
00395 
00396    /** if couldn't get them all, take our ball and go home in a snit **/
00397 
00398    if( nbad > 0 ){
00399       fprintf(stderr,"\n** failed to malloc %d MINC bricks out of %d\n\a",nbad,nv) ;
00400       for( ibr=0 ; ibr < nv ; ibr++ ){
00401         if( DBLK_ARRAY(dblk,ibr) != NULL ){
00402            free(DBLK_ARRAY(dblk,ibr)) ;
00403            mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,ibr) ) ;
00404         }
00405       }
00406       nc_close(ncid) ; EXRETURN ;
00407    }
00408 
00409    /** get scaling attributes/variables **/
00410 
00411    (void) nc_inq_vartype( ncid , im_varid , &im_type ) ;
00412 
00413    /* N.B.: we don't scale if input data is stored as floats */
00414 
00415    do_scale = (im_type==NC_BYTE || im_type==NC_SHORT || im_type==NC_INT) ;
00416 
00417    if( do_scale && AFNI_noenv("AFNI_MINC_SLICESCALE") ) do_scale = 0 ;
00418 
00419    code = nc_get_att_float( ncid,im_varid , "valid_range" , im_valid_range ) ;
00420 
00421    /** if can't get valid_range, make something up **/
00422 
00423    if( code != NC_NOERR || im_valid_range[0] >= im_valid_range[1] ){
00424 
00425       im_valid_range[0] = 0.0 ;
00426 
00427       switch( im_type ){
00428          case NC_BYTE:   im_valid_range[1] = 255.0        ; break ;
00429          case NC_SHORT:  im_valid_range[1] = 32767.0      ; break ;
00430          case NC_INT:    im_valid_range[1] = 2147483647.0 ; break ;
00431          case NC_FLOAT:
00432          case NC_DOUBLE: im_valid_range[1] = 1.0          ; break ;
00433       break ;
00434       }
00435    }
00436    inbot = im_valid_range[0] ;
00437    intop = im_valid_range[1] ;
00438    denom = intop - inbot  ;  /* always positive */
00439 
00440    /** Get range of image (per 2D slice) to which valid_range will be scaled **/
00441    /** Scaling will only be done if we get both image-min and image-max      **/
00442 
00443    if( do_scale ){
00444 
00445      code = nc_inq_varid( ncid , "image-min" , &im_min_varid ) ;
00446      if( code == NC_NOERR ){
00447        im_min = (float *) calloc(sizeof(float),nslice) ;
00448        code = nc_get_var_float( ncid , im_min_varid , im_min ) ;
00449        if( code != NC_NOERR ){ free(im_min); im_min = NULL; }
00450      }
00451 
00452      /* got im_min ==> try for im_max */
00453 
00454      if( im_min != NULL ){
00455        code = nc_inq_varid( ncid , "image-max" , &im_max_varid ) ;
00456        if( code == NC_NOERR ){
00457          im_max = (float *) calloc(sizeof(float),nslice) ;
00458          code = nc_get_var_float( ncid , im_max_varid , im_max ) ;
00459          if( code != NC_NOERR ){
00460            free(im_min); im_min = NULL; free(im_max); im_max = NULL;
00461          }
00462        }
00463      }
00464 
00465      /* 19 Mar 2003: make sure we don't scale out of range! */
00466 
00467      if( im_max != NULL && MRI_IS_INT_TYPE(DBLK_BRICK_TYPE(dblk,0)) ){
00468        float stop=0.0 , vbot,vtop ;
00469        int ii ;
00470        for( ii=0 ; ii < nslice ; ii++ ){
00471          if( im_min[ii] < im_max[ii] ){
00472            vbot = fabs(im_min[ii]) ; vtop = fabs(im_max[ii]) ;
00473            vtop = MAX(vtop,vbot) ; stop = MAX(vtop,stop) ;
00474          }
00475        }
00476        if( stop > MRI_TYPE_maxval[DBLK_BRICK_TYPE(dblk,0)] ){
00477          sfac = MRI_TYPE_maxval[DBLK_BRICK_TYPE(dblk,0)] / stop ;
00478          fprintf(stderr,"++ Scaling %s by %g to avoid overflow to %g of %s data!\n",
00479                  dkptr->brick_name, sfac, stop, MRI_TYPE_name[DBLK_BRICK_TYPE(dblk,0)] ) ;
00480        } else if( stop == 0.0 ){
00481          free(im_min); im_min = NULL; free(im_max); im_max = NULL;
00482        }
00483      }
00484 
00485    } /* end of do_scale */
00486 
00487    /** read data! **/
00488 
00489    switch( DBLK_BRICK_TYPE(dblk,0) ){  /* output datum */
00490 
00491       /* this case should never happen */
00492 
00493       default:
00494          fprintf(stderr,"\n** MINC illegal datum %d found\n",
00495                  DBLK_BRICK_TYPE(dblk,0)                     ) ;
00496          for( ibr=0 ; ibr < nv ; ibr++ ){
00497            if( DBLK_ARRAY(dblk,ibr) != NULL ){
00498               free(DBLK_ARRAY(dblk,ibr)) ;
00499               mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,ibr) ) ;
00500            }
00501          }
00502       break ;
00503 
00504       /* data is stored as bytes in AFNI */
00505 
00506       case MRI_byte:{
00507          int kk,ii,qq ; byte *br ;
00508 
00509          if( nv == 1 ){
00510             code = nc_get_var_uchar( ncid , im_varid , DBLK_ARRAY(dblk,0) ) ;
00511          } else {
00512             size_t start[4] , count[4] ;
00513             start[1] = start[2] = start[3] = 0 ;
00514             count[0] = 1 ; count[1] = nz ; count[2] = ny ; count[3] = nx ;
00515             for( ibr=0 ; ibr < nv ; ibr++ ){
00516                start[0] = ibr ;
00517                code = nc_get_vara_uchar( ncid,im_varid ,
00518                                          start,count , DBLK_ARRAY(dblk,ibr) ) ;
00519             }
00520          }
00521          if( code != NC_NOERR ) EPR(code,dkptr->brick_name,"image get_var_uchar") ;
00522 
00523          if( im_max != NULL ){                 /* must scale values */
00524            for( ibr=0 ; ibr < nv ; ibr++ ){     /* loop over bricks */
00525              br = DBLK_ARRAY(dblk,ibr) ;
00526              for( kk=0 ; kk < nz ; kk++ ){      /* loop over slices */
00527                 outbot = im_min[kk+ibr*nz] ;
00528                 outtop = im_max[kk+ibr*nz] ;
00529                 if( outbot >= outtop) continue ;            /* skip */
00530                 fac = (outtop-outbot) / denom ;
00531                 qq = kk*nxy ; outbot += 0.499 ;
00532                 for( ii=0 ; ii < nxy ; ii++ )        /* scale slice */
00533                    br[ii+qq] = (byte) ((fac*(br[ii+qq]-inbot) + outbot)*sfac) ;
00534              }
00535            }
00536          }
00537       }
00538       break ;
00539 
00540       /* data is stored as shorts in AFNI */
00541 
00542       case MRI_short:{
00543          int kk,ii,qq ; short *br ;
00544 
00545          if( nv == 1 ){
00546             code = nc_get_var_short( ncid , im_varid , DBLK_ARRAY(dblk,0) ) ;
00547          } else {
00548             size_t start[4] , count[4] ;
00549             start[1] = start[2] = start[3] = 0 ;
00550             count[0] = 1 ; count[1] = nz ; count[2] = ny ; count[3] = nx ;
00551             for( ibr=0 ; ibr < nv ; ibr++ ){
00552                start[0] = ibr ;
00553                code = nc_get_vara_short( ncid,im_varid ,
00554                                          start,count , DBLK_ARRAY(dblk,ibr) ) ;
00555             }
00556          }
00557          if( code != NC_NOERR ) EPR(code,dkptr->brick_name,"image get_var_short") ;
00558 
00559          if( im_max != NULL ){                 /* must scale values */
00560            for( ibr=0 ; ibr < nv ; ibr++ ){     /* loop over bricks */
00561              br = DBLK_ARRAY(dblk,ibr) ;
00562              for( kk=0 ; kk < nz ; kk++ ){      /* loop over slices */
00563                 outbot = im_min[kk+ibr*nz] ;
00564                 outtop = im_max[kk+ibr*nz] ;
00565                 if( outbot >= outtop) continue ;            /* skip */
00566                 fac = (outtop-outbot) / denom ;
00567                 qq = kk*nxy ; outbot += 0.499 ;
00568                 for( ii=0 ; ii < nxy ; ii++ )        /* scale slice */
00569                    br[ii+qq] = (short) ((fac*(br[ii+qq]-inbot) + outbot)*sfac) ;
00570              }
00571            }
00572          }
00573       }
00574       break ;
00575 
00576       /* data is stored as floats in AFNI */
00577 
00578       case MRI_float:{
00579          int kk,ii,qq ; float *br ;
00580 
00581          if( nv == 1 ){
00582             code = nc_get_var_float( ncid , im_varid , DBLK_ARRAY(dblk,0) ) ;
00583          } else {
00584             size_t start[4] , count[4] ;
00585             start[1] = start[2] = start[3] = 0 ;
00586             count[0] = 1 ; count[1] = nz ; count[2] = ny ; count[3] = nx ;
00587             for( ibr=0 ; ibr < nv ; ibr++ ){
00588                start[0] = ibr ;
00589                code = nc_get_vara_float( ncid,im_varid ,
00590                                          start,count , DBLK_ARRAY(dblk,ibr) ) ;
00591             }
00592          }
00593          if( code != NC_NOERR ) EPR(code,dkptr->brick_name,"image get_var_float") ;
00594 
00595          if( im_type == NC_BYTE ){              /* fix sign of bytes */
00596            for( ibr=0 ; ibr < nv ; ibr++ ){     /* loop over bricks */
00597              br = DBLK_ARRAY(dblk,ibr) ;
00598              for( ii=0 ; ii < nxyz ; ii++ )
00599                 if( br[ii] < 0.0 ) br[ii] += 256.0 ;
00600            }
00601          }
00602 
00603          if( im_max != NULL ){                 /* must scale values */
00604            for( ibr=0 ; ibr < nv ; ibr++ ){     /* loop over bricks */
00605              br = DBLK_ARRAY(dblk,ibr) ;
00606              for( kk=0 ; kk < nz ; kk++ ){      /* loop over slices */
00607                 outbot = im_min[kk+ibr*nz] ;
00608                 outtop = im_max[kk+ibr*nz] ;
00609                 if( outbot >= outtop) continue ;            /* skip */
00610                 fac = (outtop-outbot) / denom ;
00611                 qq = kk*nxy ;
00612                 for( ii=0 ; ii < nxy ; ii++ )        /* scale slice */
00613                    br[ii+qq] = (fac*(br[ii+qq]-inbot) + outbot) ;
00614              }
00615            }
00616          }
00617       }
00618       break ;
00619 
00620    } /* end of switch on output datum */
00621 
00622    /*-- throw away the trash and return --*/
00623 
00624    if( im_min != NULL ) free(im_min) ;
00625    if( im_max != NULL ) free(im_max) ;
00626    nc_close(ncid) ; EXRETURN ;
00627 }

void THD_load_mpeg THD_datablock   dblk
 

Load an MPEG dataset from disk. -----------------------------------------------------------------------

Definition at line 157 of file thd_mpegread.c.

References AFMALL, THD_datablock::brick, THD_diskptr::brick_name, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_TYPE, DESTROY_IMARR, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, free, IMARR_SUBIM, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_data_pointer(), mri_datum_size(), mri_fix_data_pointer(), mri_read_mpeg(), THD_diskptr::nvals, nz, STORAGE_BY_MPEG, and THD_diskptr::storage_mode.

Referenced by THD_load_datablock().

00158 {
00159    THD_diskptr *dkptr ;
00160    int nx,ny,nz,nv , nxy,nxyz,nxyzv , ibr,nbad , nbar ;
00161    FILE *fp ;
00162    void *ptr ;
00163    MRI_IMARR *imar ;
00164    MRI_IMAGE *im ;
00165    byte *bim , *bar ;
00166 
00167 ENTRY("THD_load_mpeg") ;
00168 
00169    /*-- check inputs --*/
00170 
00171    if( !ISVALID_DATABLOCK(dblk)                       ||
00172        dblk->diskptr->storage_mode != STORAGE_BY_MPEG ||
00173        dblk->brick == NULL                              ) EXRETURN ;
00174 
00175    dkptr = dblk->diskptr ;
00176 
00177    imar = mri_read_mpeg( dkptr->brick_name ) ;
00178    if( imar == NULL ) EXRETURN ;
00179 
00180    /*-- allocate space for data --*/
00181 
00182    nx = dkptr->dimsizes[0] ;
00183    ny = dkptr->dimsizes[1] ;  nxy   = nx * ny   ;
00184    nz = dkptr->dimsizes[2] ;  nxyz  = nxy * nz  ;
00185    nv = dkptr->nvals       ;  nxyzv = nxyz * nv ;
00186 
00187    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00188 
00189    /*-- malloc space for each brick separately --*/
00190 
00191    for( nbad=ibr=0 ; ibr < nv ; ibr++ ){
00192      if( DBLK_ARRAY(dblk,ibr) == NULL ){
00193        ptr = AFMALL(void, DBLK_BRICK_BYTES(dblk,ibr) ) ;
00194        mri_fix_data_pointer( ptr ,  DBLK_BRICK(dblk,ibr) ) ;
00195        if( ptr == NULL ) nbad++ ;
00196      }
00197    }
00198 
00199    /*-- if couldn't get them all, take our ball and go home in a snit --*/
00200 
00201    if( nbad > 0 ){
00202      fprintf(stderr,
00203              "\n** failed to malloc %d MPEG bricks out of %d\n\a",nbad,nv);
00204      for( ibr=0 ; ibr < nv ; ibr++ ){
00205        if( DBLK_ARRAY(dblk,ibr) != NULL ){
00206          free(DBLK_ARRAY(dblk,ibr)) ;
00207          mri_fix_data_pointer( NULL , DBLK_BRICK(dblk,ibr) ) ;
00208        }
00209      }
00210      fclose(fp) ; DESTROY_IMARR(imar) ; EXRETURN ;
00211    }
00212 
00213    /*-- load data from image array into sub-brick arrays! --*/
00214 
00215    nbar = mri_datum_size( DBLK_BRICK_TYPE(dblk,0) ) * nx*ny ;
00216    if( nv == 1 ){                   /* all data goes into 1 sub-brick */
00217      bar = DBLK_ARRAY(dblk,0) ;
00218      for( ibr=0 ; ibr < nz ; ibr++ ){
00219        im = IMARR_SUBIM(imar,ibr) ; bim = mri_data_pointer(im) ;
00220        memcpy( bar , bim , nbar ) ;
00221        bar += nbar ;
00222      }
00223    } else {                         /* each slice is a separate sub-brick */
00224      for( ibr=0 ; ibr < nv ; ibr++ ){
00225        bar = DBLK_ARRAY(dblk,ibr) ;
00226        im = IMARR_SUBIM(imar,ibr) ; bim = mri_data_pointer(im) ;
00227        memcpy( bar , bim , nbar ) ;
00228      }
00229    }
00230 
00231    DESTROY_IMARR(imar) ;
00232    EXRETURN ;
00233 }

void THD_load_nifti THD_datablock   dblk
 

10 May 2005: see if there is an AFNI extension; if so, load attributes from it and then edit the dataset appropriately *

Definition at line 591 of file thd_niftiread.c.

References AFMALL, AFNI_yesenv(), THD_datablock::brick, THD_diskptr::brick_name, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_NVOX, DBLK_BRICK_TYPE, THD_diskptr::dimsizes, THD_datablock::diskptr, ENTRY, far, free, complex::i, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_fix_data_pointer(), THD_diskptr::nvals, nz, complex::r, STATUS, STORAGE_BY_NIFTI, THD_diskptr::storage_mode, thd_complexscan(), and thd_floatscan().

Referenced by THD_load_datablock().

00592 {
00593    THD_diskptr *dkptr ;
00594    int nx,ny,nz,nxy,nxyz,nxyzv , nerr=0,ibr,nv, nslice ;
00595    int datum, need_copy=0 ;
00596    void *ptr ;
00597    nifti_image *nim ;
00598    nifti_brick_list NBL ;  /* holds the data read from disk */
00599 
00600 ENTRY("THD_load_nifti") ;
00601 
00602    /*-- open and read input [these errors should never occur] --*/
00603 
00604    if( !ISVALID_DATABLOCK(dblk)                        ||
00605        dblk->diskptr->storage_mode != STORAGE_BY_NIFTI ||
00606        dblk->brick == NULL                               ) EXRETURN ;
00607 
00608    dkptr = dblk->diskptr ;
00609 
00610    STATUS("calling nifti_image_read_bricks") ;
00611    NBL.nbricks = 0 ;
00612    nim = nifti_image_read_bricks( dkptr->brick_name, 0,NULL , &NBL ) ;
00613    if( nim == NULL || NBL.nbricks <= 0 ) EXRETURN ;
00614 
00615    datum = DBLK_BRICK_TYPE(dblk,0) ;  /* destination data type */
00616 
00617    /*-- determine if we need to copy the data from the
00618         bricks as loaded above because of a type conversion --*/
00619 
00620    switch( nim->datatype ){
00621      case DT_INT16:
00622      case DT_UINT8:      need_copy = (datum == MRI_float) ; break ;
00623 
00624      case DT_FLOAT32:
00625      case DT_COMPLEX64:
00626      case DT_RGB24:      need_copy = 0 ; break ;
00627 
00628      case DT_INT8:       /* these are the cases where AFNI can't */
00629      case DT_UINT16:     /* directly handle the NIFTI datatype,  */
00630      case DT_INT32:      /* so we'll convert them to floats.     */
00631      case DT_UINT32:
00632      case DT_FLOAT64:    need_copy = 1 ; break ;
00633 #if 0
00634      case DT_COMPLEX128: need_copy = 1 ; break ;
00635 #endif
00636    }
00637 
00638    /*-- various dimensions --*/
00639 
00640    nx = dkptr->dimsizes[0] ;
00641    ny = dkptr->dimsizes[1] ;  nxy   = nx * ny   ;
00642    nz = dkptr->dimsizes[2] ;  nxyz  = nxy * nz  ;
00643    nv = dkptr->nvals       ;  if( nv > NBL.nbricks ) nv = NBL.nbricks ;
00644    nxyzv = nxyz * nv ; nslice = nz*nv ;
00645 
00646    dblk->malloc_type = DATABLOCK_MEM_MALLOC ;
00647 
00648    /*------ don't need to copy data ==> just copy pointers from NBL ------*/
00649 
00650    if( !need_copy ){
00651 
00652      STATUS("copying brick pointers directly") ;
00653      for( ibr=0 ; ibr < nv ; ibr++ ){
00654        mri_fix_data_pointer( NBL.bricks[ibr] ,DBLK_BRICK(dblk,ibr) ) ;
00655        NBL.bricks[ibr] = NULL ;  /* so it won't be deleted later */
00656 
00657        if( AFNI_yesenv("AFNI_FLOATSCAN") ){  /*--- check float inputs? ---*/
00658          if( DBLK_BRICK_TYPE(dblk,ibr) == MRI_float )
00659            nerr += thd_floatscan( DBLK_BRICK_NVOX(dblk,ibr) ,
00660                                   DBLK_ARRAY(dblk,ibr)        ) ;
00661          else if( DBLK_BRICK_TYPE(dblk,ibr) == MRI_complex )
00662            nerr += thd_complexscan( DBLK_BRICK_NVOX(dblk,ibr) ,
00663                                     DBLK_ARRAY(dblk,ibr)        ) ;
00664        }
00665      }
00666      if( nerr > 0 ) fprintf(stderr ,
00667                     "** %s: found %d float errors -- see program float_scan\n",
00668                     dkptr->brick_name , nerr ) ;
00669 
00670    } else { /*---------- need to copy data ==> do some more work -----------*/
00671 
00672      register int ii ; void *nbuf ;
00673 
00674      STATUS("converting input bricks to floats") ;
00675      for( ibr=0 ; ibr < nv ; ibr++ ){
00676 
00677        if( DBLK_ARRAY(dblk,ibr) == NULL ){                     /* make space */
00678          ptr = AFMALL(void, DBLK_BRICK_BYTES(dblk,ibr) ) ;     /* for this   */
00679          mri_fix_data_pointer( ptr ,  DBLK_BRICK(dblk,ibr) ) ; /* sub-brick! */
00680        }
00681        ptr = DBLK_ARRAY(dblk,ibr) ; if( ptr == NULL ) break ;  /* bad news!! */
00682 
00683        nbuf = NBL.bricks[ibr] ;              /* data as read from NIfTI file */
00684 
00685        /* macro to convert data from type "ityp" in nbuf to float in dataset */
00686 
00687 #undef  CPF
00688 #define CPF(ityp) do{ ityp *sar = (ityp *)nbuf ; float *far = (float *)ptr ;   \
00689                       for( ii=0 ; ii < nxyz ; ii++ ) far[ii] = (float)sar[ii]; \
00690                   } while(0)
00691 
00692        /* load from nbuf into brick array (will be float or complex) */
00693 
00694        switch( nim->datatype ){
00695          case DT_UINT8:    CPF(unsigned char)  ; break ;
00696          case DT_INT8:     CPF(signed char)    ; break ;
00697          case DT_INT16:    CPF(signed short)   ; break ;
00698          case DT_UINT16:   CPF(unsigned short) ; break ;
00699          case DT_INT32:    CPF(signed int)     ; break ;
00700          case DT_UINT32:   CPF(unsigned int)   ; break ;
00701          case DT_FLOAT64:  CPF(double)         ; break ;
00702 #if 0
00703          case DT_COMPLEX128: break ;
00704 #endif
00705        }
00706 
00707        free(NBL.bricks[ibr]) ; NBL.bricks[ibr] = NULL ;
00708      }
00709    }
00710 
00711    nifti_free_NBL( &NBL ) ;  /* done with this */
00712 
00713    /*-- scale results? ---*/
00714 
00715    if( nim->scl_slope != 0.0 ){       /*--- scale results? ---*/
00716      STATUS("scaling sub-bricks") ;
00717      for( ibr=0 ; ibr < nv ; ibr++ ){
00718        if( DBLK_BRICK_TYPE(dblk,ibr) == MRI_float ){
00719          float *far = (float *) DBLK_ARRAY(dblk,ibr) ; int ii ;
00720          for( ii=0 ; ii < nxyz ; ii++ )
00721            far[ii] = nim->scl_slope * far[ii] + nim->scl_inter ;
00722        } else if( DBLK_BRICK_TYPE(dblk,ibr) == MRI_complex ){
00723          complex *car = (complex *) DBLK_ARRAY(dblk,ibr) ; int ii ;
00724          for( ii=0 ; ii < nxyz ; ii++ ){
00725            car[ii].r = nim->scl_slope * car[ii].r + nim->scl_inter ;
00726            car[ii].i = nim->scl_slope * car[ii].i + nim->scl_inter ;
00727          }
00728        }
00729      }
00730    }
00731 
00732    /*-- throw away the trash and return --*/
00733 
00734    nifti_image_free(nim) ; EXRETURN ;
00735 }

void THD_load_statistics THD_3dim_dataset   dset
 

Load the statistics of a dataset (modified Nov 15 1995) ------------------------------------------------------------------------

Definition at line 14 of file thd_bstats.c.

References ADDTO_KILL, THD_statistics::bstat, THD_3dim_dataset::dblk, DSET_BRICK, DSET_BRICK_FACTOR, INVALIDATE_BSTAT, ISVALID_3DIM_DATASET, ISVALID_STATISTIC, THD_3dim_dataset::kl, THD_brick_stats::max, THD_brick_stats::min, myXtNew, THD_statistics::nbstat, THD_datablock::nvals, THD_statistics::parent, RELOAD_STATS, REPLACE_KILL, STATISTICS_TYPE, THD_3dim_dataset::stats, THD_count_databricks(), THD_get_brick_stats(), THD_statistics::type, THD_3dim_dataset::warp_parent, and XtRealloc.

Referenced by adwarp_refashion_dataset(), AFNI_fimmer_redisplay(), AFNI_refashion_dataset(), DRAW_into_dataset(), DRAW_quit_CB(), DRAW_receiver(), fim3d_fimmer_compute(), IMREG_main(), main(), NUD_quit_CB(), output_results(), output_ts_array(), PLUTO_add_dset(), process_as_floats(), r_any_cb_apply(), r_any_cb_undo(), r_any_cb_unfill(), r_fill_resampled_data_brick(), r_gr_cb_fill(), r_HL_cb_fill(), r_INT_cb_fill(), r_wt_cb_fill(), RT_tell_afni_one(), T3D_save_file_CB(), THD_warp3D(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), and write_ts_array().

00015 {
00016    int ii , mmin , mmax , ibr , nbr ;
00017    short *brkk ;
00018    THD_brick_stats *bsold ;
00019 
00020    /*-- sanity checks --*/
00021 
00022    if( ! ISVALID_3DIM_DATASET(dset) ) return ;
00023 
00024    nbr = THD_count_databricks( dset->dblk ) ;
00025 
00026    /*-- 3/24/95: if don't get data, try for the warp parent --*/
00027 
00028    if( nbr == 0 ){
00029 
00030      if( ! ISVALID_3DIM_DATASET(dset->warp_parent) ) return ;     /* nothing */
00031      if( dset->warp_parent == dset )                 return ;
00032 
00033      RELOAD_STATS( dset->warp_parent ) ;                       /* recursion! */
00034      if( ! ISVALID_STATISTIC(dset->warp_parent->stats) ) return ; /* nothing */
00035 
00036      if( dset->stats == NULL ){                     /* create if not present */
00037        dset->stats = myXtNew( THD_statistics ) ;
00038        ADDTO_KILL( dset->kl , dset->stats ) ;
00039        dset->stats->type   = STATISTICS_TYPE ;
00040        dset->stats->parent = (XtPointer) dset ;
00041        dset->stats->bstat  = NULL ;
00042      }
00043 
00044      bsold               = dset->stats->bstat ;
00045      dset->stats->nbstat = dset->dblk->nvals ;
00046      dset->stats->bstat  = (THD_brick_stats *)
00047                             XtRealloc( (char *) bsold ,
00048                                 sizeof(THD_brick_stats) * dset->dblk->nvals ) ;
00049      if( bsold != dset->stats->bstat )
00050         REPLACE_KILL( dset->kl , bsold , dset->stats->bstat ) ;
00051 
00052      /** copy stats from warp parent for each brick **/
00053 
00054      for( ibr=0 ; ibr < dset->dblk->nvals ; ibr++ ){
00055        if( ibr < dset->warp_parent->stats->nbstat )
00056          dset->stats->bstat[ibr] = dset->warp_parent->stats->bstat[ibr] ;
00057        else
00058          INVALIDATE_BSTAT( dset->stats->bstat[ibr] ) ;
00059      }
00060 
00061      return ;
00062    }
00063 
00064    /*-- if here, have good data in this dataset --*/
00065 
00066    if( dset->stats == NULL ){                  /* create if not present */
00067      dset->stats = myXtNew( THD_statistics ) ;
00068      ADDTO_KILL( dset->kl , dset->stats ) ;
00069      dset->stats->type   = STATISTICS_TYPE ;
00070      dset->stats->parent = (XtPointer) dset ;
00071      dset->stats->bstat  = NULL ;
00072    }
00073 
00074    bsold               = dset->stats->bstat ;
00075    dset->stats->nbstat = dset->dblk->nvals ;
00076    dset->stats->bstat  = (THD_brick_stats *)
00077                           XtRealloc( (char *) bsold ,
00078                               sizeof(THD_brick_stats) * dset->dblk->nvals ) ;
00079    if( bsold != dset->stats->bstat )
00080      REPLACE_KILL( dset->kl , bsold , dset->stats->bstat ) ;
00081 
00082    /* 3/24/95: load stats for each sub-brick, not just the first */
00083 
00084    for( ibr=0 ; ibr < dset->dblk->nvals ; ibr++ ){  /* for each sub-brick */
00085      dset->stats->bstat[ibr] = THD_get_brick_stats( DSET_BRICK(dset,ibr) ) ;
00086 
00087      /* 11/21/95: allow for scaling factor that may be applied to data */
00088 
00089      if( DSET_BRICK_FACTOR(dset,ibr) > 0.0 ){
00090        dset->stats->bstat[ibr].min *= DSET_BRICK_FACTOR(dset,ibr) ;
00091        dset->stats->bstat[ibr].max *= DSET_BRICK_FACTOR(dset,ibr) ;
00092      }
00093    }
00094    return ;
00095 }

void THD_load_tcat THD_datablock   dblk
 

Load from disk the impromptu catenation.

Definition at line 129 of file thd_opentcat.c.

References DSET_ARRAY, DSET_BRICK, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_delete, DSET_load, DSET_LOADED, DSET_mallocize, DSET_NVALS, DSET_unload, EDIT_BRICK_FACTOR, EDIT_substitute_brick(), ENTRY, ISVALID_DBLK, ISVALID_DSET, mri_fix_data_pointer(), NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, THD_datablock::parent, NI_str_array::str, THD_3dim_dataset::tcat_list, THD_3dim_dataset::tcat_num, and THD_open_dataset().

Referenced by THD_load_datablock().

00130 {
00131    int ivout , dd , iv ;
00132    THD_3dim_dataset *dset_in , *dset_out ;
00133    NI_str_array *sar ;
00134 
00135 ENTRY("THD_load_tcat") ;
00136 
00137    if( !ISVALID_DBLK(dblk) ) EXRETURN ;
00138    dset_out = (THD_3dim_dataset *)dblk->parent ;
00139    if( !ISVALID_DSET(dset_out) ) EXRETURN ;
00140    sar = NI_decode_string_list( dset_out->tcat_list , "~" ) ;
00141    if( sar == NULL ) EXRETURN ;
00142    if( sar->num != dset_out->tcat_num ){ NI_delete_str_array(sar); EXRETURN; }
00143 
00144    ivout = 0 ;
00145    for( dd=0 ; dd < sar->num ; dd++ ){
00146      dset_in = THD_open_dataset( sar->str[dd] ) ;
00147      if( dset_in == NULL ){
00148        NI_delete_str_array(sar) ; DSET_unload(dset_out) ;
00149        EXRETURN ;
00150      }
00151      DSET_mallocize(dset_in) ; DSET_load(dset_in) ;
00152      if( !DSET_LOADED(dset_in) ){
00153        NI_delete_str_array(sar) ; DSET_unload(dset_out) ; DSET_delete(dset_in) ;
00154        EXRETURN ;
00155      }
00156 
00157      for( iv=0 ; iv < DSET_NVALS(dset_in) ; iv++ ){
00158        EDIT_substitute_brick( dset_out , ivout ,
00159                               DSET_BRICK_TYPE(dset_in,iv), DSET_ARRAY(dset_in,iv) );
00160        mri_fix_data_pointer( NULL , DSET_BRICK(dset_in,iv) ) ;
00161        EDIT_BRICK_FACTOR( dset_out , ivout , DSET_BRICK_FACTOR(dset_in,iv) ) ;
00162        ivout++ ;
00163      }
00164      DSET_delete(dset_in) ;
00165    }
00166 
00167    NI_delete_str_array(sar) ; EXRETURN ;
00168 }

byte* THD_makemask THD_3dim_dataset   mask_dset,
int    miv,
float    mask_bot,
float    mask_top
 

Make a byte mask from mask dataset: miv = sub-brick of input if( mask_bot <= mask_top ) then only nonzero values in this range will be used else all nonzero values in the mask will be used The input dataset should be byte-, short-, or float-valued.

The output is a byte array with 1s in "hit" locations and 0s in other locations. The number of bytes is DSET_NVOX(mask_dset). This array should be free()-d someday. If NULL is returned, some grotesque error transpired. -----------------------------------------------------------------------

Definition at line 24 of file thd_makemask.c.

References BYTEIZE, calloc, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, DSET_unload, free, ISVALID_DSET, mmm, and SHORTIZE.

Referenced by BFIT_prepare_dataset(), CORREL_main(), get_options(), HI_read_opts(), HISTO_main(), init_floatvector_array(), main(), MRG_read_opts(), PC_read_opts(), read_input_data(), SCAT_main(), SUMA_FormAfnidset(), and UC_read_opts().

00026 {
00027    byte *mmm = NULL ;
00028    int nvox , ii ;
00029 
00030    if( !ISVALID_DSET(mask_dset)    ||
00031        miv < 0                     ||
00032        miv >= DSET_NVALS(mask_dset)  ) return NULL ;
00033 
00034    nvox = DSET_NVOX(mask_dset) ;
00035 
00036    DSET_load(mask_dset) ; if( !DSET_LOADED(mask_dset) ) return NULL ;
00037 
00038    mmm = (byte *) calloc( sizeof(byte) * nvox , 1 ) ;
00039 
00040    switch( DSET_BRICK_TYPE(mask_dset,miv) ){
00041       default:
00042          free(mmm) ; DSET_unload(mask_dset) ; return NULL ;
00043 
00044       case MRI_short:{
00045          short mbot , mtop ;
00046          short *mar = (short *) DSET_ARRAY(mask_dset,miv) ;
00047          float mfac = DSET_BRICK_FACTOR(mask_dset,miv) ;
00048          if( mfac == 0.0 ) mfac = 1.0 ;
00049          if( mask_bot <= mask_top ){
00050             mbot = SHORTIZE(mask_bot/mfac) ;
00051             mtop = SHORTIZE(mask_top/mfac) ;
00052          } else {
00053             mbot = (short) -MRI_TYPE_maxval[MRI_short] ;
00054             mtop = (short)  MRI_TYPE_maxval[MRI_short] ;
00055          }
00056          for( ii=0 ; ii < nvox ; ii++ )
00057             if( mar[ii] >= mbot && mar[ii] <= mtop && mar[ii] != 0 ) mmm[ii]=1;
00058       }
00059       break ;
00060 
00061       case MRI_byte:{
00062          byte mbot , mtop ;
00063          byte *mar = (byte *) DSET_ARRAY(mask_dset,miv) ;
00064          float mfac = DSET_BRICK_FACTOR(mask_dset,miv) ;
00065          if( mfac == 0.0 ) mfac = 1.0 ;
00066          if( mask_bot <= mask_top && mask_top > 0.0 ){
00067             mbot = BYTEIZE(mask_bot/mfac) ;
00068             mtop = BYTEIZE(mask_top/mfac) ;
00069          } else {
00070             mbot = 0 ;
00071             mtop = (byte) MRI_TYPE_maxval[MRI_short] ;
00072          }
00073          for( ii=0 ; ii < nvox ; ii++ )
00074             if( mar[ii] >= mbot && mar[ii] <= mtop && mar[ii] != 0 ) mmm[ii]=1;
00075       }
00076       break ;
00077 
00078       case MRI_float:{
00079          float mbot , mtop ;
00080          float *mar = (float *) DSET_ARRAY(mask_dset,miv) ;
00081          float mfac = DSET_BRICK_FACTOR(mask_dset,miv) ;
00082          if( mfac == 0.0 ) mfac = 1.0 ;
00083          if( mask_bot <= mask_top ){
00084             mbot = (float) (mask_bot/mfac) ;
00085             mtop = (float) (mask_top/mfac) ;
00086          } else {
00087             mbot = -WAY_BIG ;
00088             mtop =  WAY_BIG ;
00089          }
00090          for( ii=0 ; ii < nvox ; ii++ )
00091             if( mar[ii] >= mbot && mar[ii] <= mtop && mar[ii] != 0 ) mmm[ii]=1;
00092       }
00093       break ;
00094    }
00095 
00096    return mmm ;
00097 }

int THD_mask_clip_neighbors int    nx,
int    ny,
int    nz,
byte   mmm,
float    clip_val,
float    tclip,
float *    mar
 

Find voxels not in the mask, but neighboring it, that are also below the clip threshold in mar[]. Add these to the mask. Repeat until done. Return value is number of voxels added. -----------------------------------------------------------------------

Definition at line 235 of file thd_automask.c.

References mmm, and nz.

Referenced by mri_automask_image().

00237 {
00238    int ii,jj,kk , ntot=0,nnew , jm,jp,j3 , km,kp,k3 , im,ip,i3 , nxy=nx*ny ;
00239 
00240    if( mmm == NULL || mar == NULL ) return 0 ;
00241 
00242    do{
00243     nnew = 0 ;
00244     for( kk=1 ; kk < nz-1 ; kk++ ){
00245      k3 = kk*nxy ;
00246      for( jj=1 ; jj < ny-1 ; jj++ ){
00247       j3 = k3 + jj*nx ;
00248       for( ii=1 ; ii < nx-1 ; ii++ ){
00249        i3 = ii+j3 ;
00250        if( mmm[i3] ||                                             /* in mask */
00251            (mar[i3] >= clip_val && mar[i3] <= tclip) ) continue ; /* or is OK */
00252 
00253        /* If here, voxel IS NOT in mask, and IS below threshold.
00254           If any neighbors are also in mask, then add it to mask. */
00255 
00256        if( mmm[i3-1]   || mmm[i3+1]   ||
00257            mmm[i3-nx]  || mmm[i3+nx]  ||
00258            mmm[i3-nxy] || mmm[i3+nxy]   ){ mmm[i3] = 1; nnew++; }
00259     }}}
00260     ntot += nnew ;
00261    } while( nnew > 0 ) ;
00262 
00263    return ntot ;
00264 }

void THD_mask_clust int    nx,
int    ny,
int    nz,
byte   mmm
 

Find the biggest cluster of nonzeros in the byte mask mmm. --------------------------------------------------------------------

Definition at line 468 of file thd_automask.c.

References AFMALL, CPUT, dall, DALL, free, IJK_TO_THREE, ININFO_message(), malloc, mmm, nz, and THREE_TO_IJK.

Referenced by main(), make_peel_mask(), MRI_autobbox(), mri_automask_image(), mri_brainormalize(), mri_warp3D_align_setup(), THD_orient_guess(), and zedit_mask().

00469 {
00470    int ii,jj,kk, icl ,  nxy,nxyz , ijk , ijk_last , mnum ;
00471    int ip,jp,kp , im,jm,km ;
00472    int nbest ; short *ibest, *jbest , *kbest ;
00473    int nnow  ; short *inow , *jnow  , *know  ; int nall ;
00474 
00475    if( mmm == NULL ) return ;
00476 
00477    nxy = nx*ny ; nxyz = nxy * nz ;
00478 
00479    nbest = 0 ;
00480    ibest = AFMALL(short, sizeof(short)) ;
00481    jbest = AFMALL(short, sizeof(short)) ;
00482    kbest = AFMALL(short, sizeof(short)) ;
00483 
00484    /*--- scan through array, find nonzero point, build a cluster, ... ---*/
00485 
00486    ijk_last = 0 ; if( dall < DALL ) dall = DALL ;
00487    while(1) {
00488      /* find next nonzero point */
00489 
00490      for( ijk=ijk_last ; ijk < nxyz ; ijk++ ) if( mmm[ijk] ) break ;
00491      if( ijk == nxyz ) break ;  /* didn't find any! */
00492 
00493      ijk_last = ijk+1 ;         /* start here next time */
00494 
00495      /* init current cluster list with this point */
00496 
00497      mmm[ijk] = 0 ;                                /* clear found point */
00498      nall = DALL ;                                 /* # allocated pts */
00499      nnow = 1 ;                                    /* # pts in cluster */
00500      inow = (short *) malloc(sizeof(short)*DALL) ; /* coords of pts */
00501      jnow = (short *) malloc(sizeof(short)*DALL) ;
00502      know = (short *) malloc(sizeof(short)*DALL) ;
00503      IJK_TO_THREE(ijk, inow[0],jnow[0],know[0] , nx,nxy) ;
00504 
00505      /*--
00506         for each point in cluster:
00507            check neighboring points for nonzero entries in mmm
00508            enter those into cluster (and clear them in mmm)
00509            continue until end of cluster is reached
00510              (note that cluster is expanding as we progress)
00511      --*/
00512 
00513      for( icl=0 ; icl < nnow ; icl++ ){
00514        ii = inow[icl] ; jj = jnow[icl] ; kk = know[icl] ;
00515        im = ii-1      ; jm = jj-1      ; km = kk-1 ;
00516        ip = ii+1      ; jp = jj+1      ; kp = kk+1 ;
00517 
00518        if( im >= 0 ) CPUT(im,jj,kk) ;
00519        if( ip < nx ) CPUT(ip,jj,kk) ;
00520        if( jm >= 0 ) CPUT(ii,jm,kk) ;
00521        if( jp < ny ) CPUT(ii,jp,kk) ;
00522        if( km >= 0 ) CPUT(ii,jj,km) ;
00523        if( kp < nz ) CPUT(ii,jj,kp) ;
00524      }
00525 
00526      /* see if now cluster is larger than best yet */
00527 
00528      if( nnow > nbest ){                         /* now is bigger; */
00529        free(ibest) ; free(jbest) ; free(kbest) ; /* replace best  */
00530        nbest = nnow ; ibest = inow ;             /* with now     */
00531        jbest = jnow ; kbest = know ;
00532      } else {                                    /* old is bigger */
00533        free(inow) ; free(jnow) ; free(know) ;    /* toss now     */
00534      }
00535 
00536    } /* loop ends when all nonzero points are clustered */
00537 
00538    /* put 1's back in at all points in best cluster */
00539 
00540    for( icl=0 ; icl < nbest ; icl++ ){
00541       ijk = THREE_TO_IJK(ibest[icl],jbest[icl],kbest[icl],nx,nxy) ;
00542       mmm[ijk] = 1 ;
00543    }
00544    free(ibest) ; free(jbest) ; free(kbest) ;
00545 
00546    if( verb ) ININFO_message("Largest cluster has %d voxels\n",nbest) ;
00547 
00548    return ;
00549 }

void THD_mask_dilate int    nx,
int    ny,
int    nz,
byte   mmm,
int    ndil
 

Dilate a mask - that is, fill in zero voxels that have at least ndil neighbors in the mask. The neighbors are the 18 voxels closest in 3D (nearest and next-nearest neighbors). ----------------------------------------------------------------------------

Definition at line 651 of file thd_automask.c.

References calloc, free, mmm, and nz.

Referenced by main(), and mri_brainormalize().

00652 {
00653    int ii,jj,kk , jy,kz, im,jm,km , ip,jp,kp , num ;
00654    int nxy=nx*ny , nxyz=nxy*nz ;
00655    byte *nnn ;
00656 
00657    if( mmm == NULL ) return ;
00658         if( ndil < 1  ) ndil =  1 ;
00659    else if( ndil > 17 ) ndil = 17 ;
00660 
00661    nnn = (byte*)calloc(sizeof(byte),nxyz) ;  /* mask of dilated voxels */
00662 
00663    /* mark exterior voxels neighboring enough interior voxels */
00664 
00665    for( kk=0 ; kk < nz ; kk++ ){
00666     kz = kk*nxy ; km = kz-nxy ; kp = kz+nxy ;
00667          if( kk == 0    ) km = kz ;
00668     else if( kk == nz-1 ) kp = kz ;
00669 
00670     for( jj=0 ; jj < ny ; jj++ ){
00671      jy = jj*nx ; jm = jy-nx ; jp = jy+nx ;
00672           if( jj == 0    ) jm = jy ;
00673      else if( jj == ny-1 ) jp = jy ;
00674 
00675      for( ii=0 ; ii < nx ; ii++ ){
00676        if( mmm[ii+jy+kz] == 0 ){           /* count nonzero nbhrs */
00677          im = ii-1 ; ip = ii+1 ;
00678               if( ii == 0    ) im = 0 ;
00679          else if( ii == nx-1 ) ip = ii ;
00680          num =  mmm[im+jy+km]
00681               + mmm[ii+jm+km] + mmm[ii+jy+km] + mmm[ii+jp+km]
00682               + mmm[ip+jy+km]
00683               + mmm[im+jm+kz] + mmm[im+jy+kz] + mmm[im+jp+kz]
00684               + mmm[ii+jm+kz]                 + mmm[ii+jp+kz]
00685               + mmm[ip+jm+kz] + mmm[ip+jy+kz] + mmm[ip+jp+kz]
00686               + mmm[im+jy+kp]
00687               + mmm[ii+jm+kp] + mmm[ii+jy+kp] + mmm[ii+jp+kp]
00688               + mmm[ip+jy+kp] ;
00689          if( num >= ndil ) nnn[ii+jy+kz] = 1 ;  /* mark to dilate */
00690        }
00691    } } }
00692 
00693    for( ii=0 ; ii < nxyz ; ii++ )            /* actually dilate */
00694      if( nnn[ii] ) mmm[ii] = 1 ;
00695 
00696    free(nnn) ; return ;
00697 }

void THD_mask_erode int    nx,
int    ny,
int    nz,
byte   mmm
 

Erode away nonzero voxels that aren't neighbored by mostly other nonzero voxels. Then restore those that were eroded that are neighbors of survivors. The neighbors are the 18 voxels closest in 3D (nearest and next-nearest neighbors). ----------------------------------------------------------------------------

Definition at line 558 of file thd_automask.c.

References calloc, free, ININFO_message(), mmm, nz, and verb.

Referenced by make_peel_mask(), MRI_autobbox(), mri_automask_image(), mri_brainormalize(), mri_warp3D_align_setup(), and zedit_mask().

00559 {
00560    int ii,jj,kk , jy,kz, im,jm,km , ip,jp,kp , num ;
00561    int nxy=nx*ny , nxyz=nxy*nz ;
00562    byte *nnn ;
00563 
00564    if( mmm == NULL ) return ;
00565 
00566    nnn = (byte*)calloc(sizeof(byte),nxyz) ;  /* mask of eroded voxels */
00567 
00568    /* mark interior voxels that don't have 17 out of 18 nonzero nbhrs */
00569 
00570    for( kk=0 ; kk < nz ; kk++ ){
00571     kz = kk*nxy ; km = kz-nxy ; kp = kz+nxy ;
00572          if( kk == 0    ) km = kz ;
00573     else if( kk == nz-1 ) kp = kz ;
00574 
00575     for( jj=0 ; jj < ny ; jj++ ){
00576      jy = jj*nx ; jm = jy-nx ; jp = jy+nx ;
00577           if( jj == 0    ) jm = jy ;
00578      else if( jj == ny-1 ) jp = jy ;
00579 
00580      for( ii=0 ; ii < nx ; ii++ ){
00581        if( mmm[ii+jy+kz] ){           /* count nonzero nbhrs */
00582          im = ii-1 ; ip = ii+1 ;
00583               if( ii == 0    ) im = 0 ;
00584          else if( ii == nx-1 ) ip = ii ;
00585          num =  mmm[im+jy+km]
00586               + mmm[ii+jm+km] + mmm[ii+jy+km] + mmm[ii+jp+km]
00587               + mmm[ip+jy+km]
00588               + mmm[im+jm+kz] + mmm[im+jy+kz] + mmm[im+jp+kz]
00589               + mmm[ii+jm+kz]                 + mmm[ii+jp+kz]
00590               + mmm[ip+jm+kz] + mmm[ip+jy+kz] + mmm[ip+jp+kz]
00591               + mmm[im+jy+kp]
00592               + mmm[ii+jm+kp] + mmm[ii+jy+kp] + mmm[ii+jp+kp]
00593               + mmm[ip+jy+kp] ;
00594          if( num < 17 ) nnn[ii+jy+kz] = 1 ;  /* mark to erode */
00595        }
00596    } } }
00597 
00598    for( jj=ii=0 ; ii < nxyz ; ii++ )            /* actually erode */
00599      if( nnn[ii] ){ mmm[ii] = 0 ; jj++ ; }
00600 
00601    if( verb && jj > 0 ) ININFO_message("Eroded   %d voxels\n",jj) ;
00602 
00603    /* re-dilate eroded voxels that are next to survivors */
00604 
00605 #ifdef USE_DILATE
00606    for( kk=0 ; kk < nz ; kk++ ){
00607     kz = kk*nxy ; km = kz-nxy ; kp = kz+nxy ;
00608          if( kk == 0    ) km = kz ;
00609     else if( kk == nz-1 ) kp = kz ;
00610 
00611     for( jj=0 ; jj < ny ; jj++ ){
00612      jy = jj*nx ; jm = jy-nx ; jp = jy+nx ;
00613           if( jj == 0    ) jm = jy ;
00614      else if( jj == ny-1 ) jp = jy ;
00615 
00616      for( ii=0 ; ii < nx ; ii++ ){
00617        if( nnn[ii+jy+kz] ){           /* was eroded */
00618          im = ii-1 ; ip = ii+1 ;
00619               if( ii == 0    ) im = 0 ;
00620          else if( ii == nx-1 ) ip = ii ;
00621          nnn[ii+jy+kz] =              /* see if has any nbhrs */
00622                mmm[im+jy+km]
00623             || mmm[ii+jm+km] || mmm[ii+jy+km] || mmm[ii+jp+km]
00624             || mmm[ip+jy+km]
00625             || mmm[im+jm+kz] || mmm[im+jy+kz] || mmm[im+jp+kz]
00626             || mmm[ii+jm+kz]                  || mmm[ii+jp+kz]
00627             || mmm[ip+jm+kz] || mmm[ip+jy+kz] || mmm[ip+jp+kz]
00628             || mmm[im+jy+kp]
00629             || mmm[ii+jm+kp] || mmm[ii+jy+kp] || mmm[ii+jp+kp]
00630             || mmm[ip+jy+kp] ;
00631        }
00632    } } }
00633 
00634    /* actually do the dilation */
00635 
00636    for( jj=ii=0 ; ii < nxyz ; ii++ )
00637      if( nnn[ii] ){ mmm[ii] = 1 ; jj++ ; }
00638 
00639    if( verb && jj > 0 ) ININFO_message("Restored %d eroded voxels\n",jj) ;
00640 #endif
00641 
00642    free(nnn) ; return ;
00643 }

int THD_mask_fillin_completely int    nx,
int    ny,
int    nz,
byte   mmm,
int    nside
 

Fill in a byte mask, repeatedly until it doesn't fill any more. Return value is number of voxels filled. ------------------------------------------------------------------------

Definition at line 431 of file thd_automask.c.

References ENTRY, mmm, nz, RETURN, and THD_mask_fillin_once().

Referenced by main(), and mri_automask_image().

00432 {
00433    int nfill=0 , kfill ;
00434 
00435 ENTRY("THD_mask_fillin_completely") ;
00436 
00437    do{
00438       kfill = THD_mask_fillin_once( nx,ny,nz , mmm , nside ) ;
00439       nfill += kfill ;
00440    } while( kfill > 0 ) ;
00441 
00442    RETURN(nfill) ;
00443 }

int THD_mask_fillin_once int    nx,
int    ny,
int    nz,
byte   mmm,
int    nside
 

Fill in a byte mask. Filling is done by looking to each side (plus/minus) of a non-filled voxel, and seeing if there is a filled voxel on both sides. This looking is done parallel to the x-, y-, and z-axes, out to distance nside voxels.

  • nx,ny,nz = dimensions of mask
  • mmm = mask itself (will be altered)
  • nside = width of fill in look to each side
  • Return value is number of filled in voxels -----------------------------------------------------------------------

Definition at line 277 of file thd_automask.c.

References AFMALL, ENTRY, free, mmm, nz, and RETURN.

Referenced by mri_automask_image(), mri_brainormalize(), SUMA_SurfGridIntersect(), and THD_mask_fillin_completely().

00278 {
00279    int ii,jj,kk , nsx,nsy,nsz , nxy,nxyz , iv,jv,kv,ll , nfill ;
00280    byte *nnn ;
00281    int nx2,nx3,nx4 , nxy2,nxy3,nxy4 ;
00282 
00283 ENTRY("THD_mask_fillin_once") ;
00284 
00285    if( mmm == NULL || nside <= 0 ) RETURN(0) ;
00286 
00287    nsx = (nx-1)/2 ; if( nsx > nside ) nsx = nside ;
00288    nsy = (ny-1)/2 ; if( nsy > nside ) nsy = nside ;
00289    nsz = (nz-1)/2 ; if( nsz > nside ) nsz = nside ;
00290 
00291    if( nsx == 0 && nsy == 0 && nsz == 0 ) RETURN(0) ;
00292 
00293 #ifdef DEBUG
00294    fprintf(stderr,"THD_mask_fillin_once: nsx=%d nsy=%d nsz=%d\n",nsx,nsy,nsz);
00295 #endif
00296 
00297    nxy = nx*ny ; nxyz = nxy*nz ; nfill = 0 ;
00298 
00299    nx2  = 2*nx  ; nx3  = 3*nx  ; nx4  = 4*nx  ;
00300    nxy2 = 2*nxy ; nxy3 = 3*nxy ; nxy4 = 4*nxy ;
00301 
00302    nnn = AFMALL(byte, nxyz) ;  /* stores filled in values */
00303 
00304    /* loop over voxels */
00305 
00306 #define FILLVOX                                     \
00307  do{ nnn[iv] = 1; nfill++; goto NextVox; } while(0)
00308 
00309    for( kk=nsz ; kk < nz-nsz ; kk++ ){
00310      kv = kk*nxy ;
00311      for( jj=nsy ; jj < ny-nsy ; jj++ ){
00312        jv = jj*nx + kv ;
00313        for( ii=nsx ; ii < nx-nsx ; ii++ ){
00314          iv = ii+jv ;
00315          if( mmm[iv] ) continue ;     /* already filled */
00316 
00317          /* check in +x direction, then -x if +x hits */
00318 
00319          switch( nsx ){
00320            case 1:
00321              if( mmm[iv+1] && mmm[iv-1] ) FILLVOX;
00322            break ;
00323 
00324            case 2:
00325              if( (mmm[iv+1]||mmm[iv+2]) &&
00326                  (mmm[iv-1]||mmm[iv-2])   ) FILLVOX;
00327            break ;
00328 
00329            case 3:
00330              if( (mmm[iv+1]||mmm[iv+2]||mmm[iv+3]) &&
00331                  (mmm[iv-1]||mmm[iv-2]||mmm[iv-3])   ) FILLVOX;
00332            break ;
00333 
00334            case 4:
00335              if( (mmm[iv+1]||mmm[iv+2]||mmm[iv+3]||mmm[iv+4]) &&
00336                  (mmm[iv-1]||mmm[iv-2]||mmm[iv-3]||mmm[iv-4])   ) FILLVOX;
00337            break ;
00338 
00339            default:
00340              for( ll=1 ; ll <= nsx ; ll++ ) if( mmm[iv+ll] ) break ;
00341              if( ll <= nsx ){
00342                for( ll=1 ; ll <= nsx ; ll++ ) if( mmm[iv-ll] ) break ;
00343                if( ll <= nsx ) FILLVOX;
00344              }
00345            break ;
00346          }
00347 
00348          /* check in +y direction, then -y if +y hits */
00349 
00350          switch( nsy ){
00351            case 1:
00352              if( mmm[iv+nx] && mmm[iv-nx] ) FILLVOX;
00353            break ;
00354 
00355            case 2:
00356              if( (mmm[iv+nx]||mmm[iv+nx2]) &&
00357                  (mmm[iv-nx]||mmm[iv-nx2])   ) FILLVOX;
00358            break ;
00359 
00360            case 3:
00361              if( (mmm[iv+nx]||mmm[iv+nx2]||mmm[iv+nx3]) &&
00362                  (mmm[iv-nx]||mmm[iv-nx2]||mmm[iv-nx3])   ) FILLVOX;
00363            break ;
00364 
00365            case 4:
00366              if( (mmm[iv+nx]||mmm[iv+nx2]||mmm[iv+nx3]||mmm[iv+nx4]) &&
00367                  (mmm[iv-nx]||mmm[iv-nx2]||mmm[iv-nx3]||mmm[iv-nx4])   ) FILLVOX;
00368            break ;
00369 
00370            default:
00371              for( ll=1 ; ll <= nsy ; ll++ ) if( mmm[iv+ll*nx] ) break ;
00372              if( ll <= nsy ){
00373                for( ll=1 ; ll <= nsy ; ll++ ) if( mmm[iv-ll*nx] ) break ;
00374                if( ll <= nsy ) FILLVOX;
00375              }
00376            break ;
00377          }
00378 
00379          /* check in +z direction, then -z if +z hits */
00380 
00381          switch( nsz ){
00382            case 1:
00383              if( mmm[iv+nxy] && mmm[iv-nxy] ) FILLVOX;
00384            break ;
00385 
00386            case 2:
00387              if( (mmm[iv+nxy]||mmm[iv+nxy2]) &&
00388                  (mmm[iv-nxy]||mmm[iv-nxy2])   ) FILLVOX;
00389            break ;
00390 
00391            case 3:
00392              if( (mmm[iv+nxy]||mmm[iv+nxy2]||mmm[iv+nxy3]) &&
00393                  (mmm[iv-nxy]||mmm[iv-nxy2]||mmm[iv-nxy3])   ) FILLVOX;
00394            break ;
00395 
00396            case 4:
00397              if( (mmm[iv+nxy]||mmm[iv+nxy2]||mmm[iv+nxy3]||mmm[iv+nxy4]) &&
00398                  (mmm[iv-nxy]||mmm[iv-nxy2]||mmm[iv-nxy3]||mmm[iv-nxy4])   ) FILLVOX;
00399            break ;
00400 
00401            default:
00402              for( ll=1 ; ll <= nsz ; ll++ ) if( mmm[iv+ll*nxy] ) break ;
00403              if( ll <= nsz ){
00404                for( ll=1 ; ll <= nsz ; ll++ ) if( mmm[iv-ll*nxy] ) break ;
00405                if( ll <= nsz ) FILLVOX;
00406              }
00407            break ;
00408          }
00409 
00410          NextVox: ; /* end of loop over ii */
00411    } } }
00412 
00413    /* copy fills back into mmm */
00414 
00415    if( nfill > 0 ){
00416      for( iv=0 ; iv < nxyz ; iv++ ) if( nnn[iv] ) mmm[iv] = 1 ;
00417    }
00418 
00419 #ifdef DEBUG
00420    fprintf(stderr,"THD_mask_fillin_once: nfill=%d\n",nfill) ;
00421 #endif
00422 
00423    free(nnn) ; RETURN(nfill) ;
00424 }

THD_ivec3 THD_matrix_to_orientation THD_mat33    R
 

  • Input = matrix that transforms (i,j,k) indexes to RAI (x,y,z) coords.
    • Output = AFNI orientation codes for (i,j,k) axes.
    • The method is to find which permutation of (x,y,z) has the smallest angle to the (i,j,k) axes directions.
    • 27 Aug 2003 - RWCox -----------------------------------------------------------------------------

Definition at line 11 of file thd_mattor.c.

References DMAT_DET, DMAT_MUL, i, LOAD_DMAT, LOAD_IVEC3, LOAD_ZERO_DMAT, THD_dmat33::mat, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, p, q, r, and UNLOAD_MAT.

Referenced by SUMA_OpenDX_Read_CruiseVolHead(), and THD_open_nifti().

00012 {
00013    double xi,xj,xk , yi,yj,yk , zi,zj,zk , val,detQ,detP ;
00014    THD_dmat33 P , Q , M ;
00015    THD_ivec3 vor ;
00016    int i,j,k,p,q,r , ibest,jbest,kbest,pbest,qbest,rbest ;
00017    double vbest ;
00018 
00019    LOAD_IVEC3(vor,ORI_R2L_TYPE,ORI_A2P_TYPE,ORI_I2S_TYPE) ; /* default */
00020 
00021    UNLOAD_MAT(R,xi,xj,xk,yi,yj,yk,zi,zj,zk) ;
00022 
00023    /* normalize column vectors to get unit vectors along each ijk-axis */
00024 
00025    val = sqrt( xi*xi + yi*yi + zi*zi ) ;
00026    if( val == 0.0 ){ xi  = 1.0 ; yi  = 0.0 ; zi  = 0.0 ; }
00027    else            { xi /= val ; yi /= val ; zi /= val ; }
00028 
00029    val = sqrt( xj*xj + yj*yj + zj*zj ) ;
00030    if( val == 0.0 ){ xj  = 0.0 ; yj  = 1.0 ; zj  = 0.0 ; }
00031    else            { xj /= val ; yj /= val ; zj /= val ; }
00032 
00033    val = xi*xj + yi*yj + zi*zj ;    /* orthgonalize col #2 to col #1 */
00034    if( fabs(val) > 1.e-5 ){
00035      xj -= val*xi ; yj -= val*yi ; zj -= val*zi ;
00036      val = sqrt( xj*xj + yj*yj + zj*zj ) ;
00037      xj /= val ; yj /= val ; zj /= val ;
00038    }
00039 
00040    val = sqrt( xk*xk + yk*yk + zk*zk ) ;
00041    if( val == 0.0 ){ xk = yi*zj-zi*yj; yk = zi*xj-zj*xi ; zk=xi*yj-yi*xj ; }
00042    else            { xk /= val ; yk /= val ; zk /= val ; }
00043 
00044    val = xi*xk + yi*yk + zi*zk ;    /* orthogonalize col #3 to col #1 */
00045    if( fabs(val) > 1.e-5 ){
00046      xk -= val*xi ; yk -= val*yi ; zk -= val*zi ;
00047      val = sqrt( xk*xk + yk*yk + zk*zk ) ;
00048      xk /= val ; yk /= val ; zk /= val ;
00049    }
00050    val = xj*xk + yj*yk + zj*zk ;    /* and to col #2 */
00051    if( fabs(val) > 1.e-5 ){
00052      xk -= val*xj ; yk -= val*yj ; zk -= val*zj ;
00053      val = sqrt( xk*xk + yk*yk + zk*zk ) ;
00054      xk /= val ; yk /= val ; zk /= val ;
00055    }
00056 
00057    LOAD_DMAT(Q,xi,xj,xk,yi,yj,yk,zi,zj,zk) ;
00058 
00059    /* at this point, Q is the rotation matrix from the (i,j,k) to (x,y,z) axes */
00060 
00061    detQ = DMAT_DET(Q) ;
00062    if( detQ == 0.0 ) return vor ; /* shouldn't happen unless user is a dufis or oufis */
00063 
00064    /* build and test all possible +1/-1 permutation matrices */
00065 
00066    vbest = -666.0 ; ibest=pbest=qbest=rbest=1 ; jbest=2 ; kbest=3 ;
00067    for( i=1 ; i <= 3 ; i++ ){     /* i = column number to use for row #1 */
00068     for( j=1 ; j <= 3 ; j++ ){    /* j = column number to use for row #2 */
00069      if( i == j ) continue ;
00070       for( k=1 ; k <= 3 ; k++ ){  /* k = column number to use for row #3 */
00071        if( i == k || j == k ) continue ;
00072        LOAD_ZERO_DMAT(P) ;
00073        for( p=-1 ; p <= 1 ; p+=2 ){    /* p,q,r are -1 or +1      */
00074         for( q=-1 ; q <= 1 ; q+=2 ){   /* and go into rows #1,2,3 */
00075          for( r=-1 ; r <= 1 ; r+=2 ){
00076            P.mat[0][i-1] = p ; P.mat[1][j-1] = q ; P.mat[2][k-1] = r ;
00077            detP = DMAT_DET(P) ;                 /* sign of permutation */
00078            if( detP * detQ <= 0.0 ) continue ;  /* doesn't match sign of Q */
00079            M = DMAT_MUL(P,Q) ;
00080 
00081            /* we want the largest trace(M) == smallest angle to P axes */
00082            /* actual angle = 2.0*acos(0.5*sqrt(1.0+vbest)) (in radians) */
00083 
00084            val = M.mat[0][0] + M.mat[1][1] + M.mat[2][2] ; /* trace */
00085            if( val > vbest ){
00086              vbest = val ;
00087              ibest = i ; jbest = j ; kbest = k ;
00088              pbest = p ; qbest = q ; rbest = r ;
00089 #if 0
00090 fprintf(stderr,"mattor: vbest=%g (%g) i=%d j=%d k=%d p=%d q=%d r=%d\n",
00091         val, 2.0*acos(0.5*sqrt(1.0+vbest))*(180.0/3.14159265) , i,j,k,p,q,r) ;
00092 #endif
00093            }
00094    }}}}}}
00095 
00096    switch( ibest*pbest ){
00097      case  1: i = ORI_R2L_TYPE ; break ;  /* xbest = +x-DICOM */
00098      case -1: i = ORI_L2R_TYPE ; break ;  /* xbest = -x-DICOM */
00099      case  2: i = ORI_A2P_TYPE ; break ;  /* xbest = +y-DICOM */
00100      case -2: i = ORI_P2A_TYPE ; break ;  /* xbest = -y-DICOM */
00101      case  3: i = ORI_I2S_TYPE ; break ;  /* xbest = +z-DICOM */
00102      case -3: i = ORI_S2I_TYPE ; break ;  /* xbest = -z-DICOM */
00103    }
00104 
00105    switch( jbest*qbest ){
00106      case  1: j = ORI_R2L_TYPE ; break ;
00107      case -1: j = ORI_L2R_TYPE ; break ;
00108      case  2: j = ORI_A2P_TYPE ; break ;
00109      case -2: j = ORI_P2A_TYPE ; break ;
00110      case  3: j = ORI_I2S_TYPE ; break ;
00111      case -3: j = ORI_S2I_TYPE ; break ;
00112    }
00113 
00114    switch( kbest*rbest ){
00115      case  1: k = ORI_R2L_TYPE ; break ;
00116      case -1: k = ORI_L2R_TYPE ; break ;
00117      case  2: k = ORI_A2P_TYPE ; break ;
00118      case -2: k = ORI_P2A_TYPE ; break ;
00119      case  3: k = ORI_I2S_TYPE ; break ;
00120      case -3: k = ORI_S2I_TYPE ; break ;
00121    }
00122 
00123    LOAD_IVEC3(vor,i,j,k) ; return vor ;
00124 }

MRI_IMAGE* THD_mean_brick THD_3dim_dataset   dset
 

Compute mean brick of a dataset. [15 Apr 2005 - RWCox] -------------------------------------------------------------------

Definition at line 47 of file thd_median.c.

References calloc, DSET_BRICK, DSET_BRICK_FACTOR, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, ENTRY, free, ISVALID_DSET, MRI_FLOAT_PTR, mri_new_conforming, mri_scale_to_float(), RETURN, and THD_extract_array().

00048 {
00049    int nvox , nvals , ii , jj ;
00050    MRI_IMAGE *tsim , *medim ;
00051    float *medar , sum,fac ;
00052    float *tsar ;
00053 
00054 ENTRY("THD_mean_brick") ;
00055 
00056    if( !ISVALID_DSET(dset) ) RETURN(NULL) ;
00057    DSET_load(dset) ;
00058    if( !DSET_LOADED(dset) ) RETURN(NULL) ;
00059 
00060    nvals = DSET_NVALS(dset)   ; fac = 1.0 / nvals ;
00061    tsim  = DSET_BRICK(dset,0) ;
00062 
00063    if( nvals == 1 ){
00064      medim = mri_scale_to_float( DSET_BRICK_FACTOR(dset,0), tsim ) ;
00065      RETURN(medim) ;
00066    }
00067 
00068    medim = mri_new_conforming( tsim , MRI_float ) ;
00069    medar = MRI_FLOAT_PTR(medim) ;
00070    nvox  = DSET_NVOX(dset) ;
00071 
00072    tsar = (float *) calloc( sizeof(float),nvals+1 ) ;
00073    for( ii=0 ; ii < nvox ; ii++ ){
00074       THD_extract_array( ii , dset , 0 , tsar ) ;
00075       for( sum=0.0,jj=0 ; jj < nvals ; jj++ ) sum += tsar[jj] ;
00076       medar[ii] = fac * sum ;
00077    }
00078 
00079    free(tsar) ; RETURN(medim) ;
00080 }

MRI_IMAGE* THD_median_brick THD_3dim_dataset   dset
 

Compute median brick of a dataset - 12 Aug 2001

Definition at line 9 of file thd_median.c.

References calloc, DSET_BRICK, DSET_BRICK_FACTOR, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, ENTRY, free, ISVALID_DSET, MRI_FLOAT_PTR, mri_new_conforming, mri_scale_to_float(), qmed_float(), RETURN, and THD_extract_array().

Referenced by main(), THD_autobbox(), THD_automask(), and THD_outlier_count().

00010 {
00011    int nvox , nvals , ii ;
00012    MRI_IMAGE *tsim , *medim ;
00013    float *medar ;
00014    float *tsar ;  /* 05 Nov 2001 */
00015 
00016 ENTRY("THD_median_brick") ;
00017 
00018    if( !ISVALID_DSET(dset) ) RETURN(NULL) ;
00019    DSET_load(dset) ;
00020    if( !DSET_LOADED(dset) ) RETURN(NULL) ;
00021 
00022    nvals = DSET_NVALS(dset) ;
00023    tsim  = DSET_BRICK(dset,0) ;
00024 
00025    if( nvals == 1 ){
00026      medim = mri_scale_to_float( DSET_BRICK_FACTOR(dset,0), tsim ) ;
00027      RETURN(medim) ;
00028    }
00029 
00030    medim = mri_new_conforming( tsim , MRI_float ) ;
00031    medar = MRI_FLOAT_PTR(medim) ;
00032    nvox  = DSET_NVOX(dset) ;
00033 
00034    tsar = (float *) calloc( sizeof(float),nvals+1 ) ; /* 05 Nov 2001 */
00035    for( ii=0 ; ii < nvox ; ii++ ){
00036       THD_extract_array( ii , dset , 0 , tsar ) ;     /* 05 Nov 2001 */
00037       medar[ii] = qmed_float( nvals , tsar ) ;
00038    }
00039 
00040    free(tsar) ; RETURN(medim) ;
00041 }

int THD_mkdir char *    pathname
 

Create a directory. Returns 1 if OK, 0 if not.

Definition at line 46 of file thd_filestuff.c.

References free, THD_filename_ok(), THD_is_directory(), and THD_is_ondisk().

Referenced by mri_imcount_mpeg(), and mri_read_mpeg().

00047 {
00048    int lp , ii , jj ;
00049    char *pnam ;
00050 
00051    /* check if input is OK, or if it already exists */
00052 
00053    if( !THD_filename_ok(pathname) ) return 0 ;
00054    if(  THD_is_ondisk  (pathname) ) return THD_is_directory(pathname) ;
00055 
00056    pnam = strdup(pathname) ;  /* modifiable copy */
00057    lp = strlen(pnam) ; ii = 0 ;
00058 
00059    /* loop over path segments, creating them if needed */
00060 
00061    while(1){
00062 
00063      /* advance ii to point to end of next path segment,
00064         at the next '/' character, or at the end of pnam */
00065 
00066      ii += strspn(pnam+ii,"/") ; ii += strcspn(pnam+ii,"/") ;
00067 
00068      /* insert a NUL to replace the '/', temporarily */
00069 
00070      if( ii < lp ) pnam[ii] = '\0' ;
00071 
00072      /* if this segment doesn't already exist, create it */
00073 
00074      if( !THD_is_directory(pnam) ){
00075        jj = mkdir( pnam , 0755 ) ;
00076        if( jj != 0 ){ free(pnam); return 0; } /* bad */
00077      }
00078 
00079      /* if reached end of path string, we're done */
00080 
00081      if( ii == lp ){ free(pnam); return 1; }  /* good */
00082 
00083      /* reinsert '/' if it was excised */
00084 
00085      pnam[ii] = '/' ;
00086    }
00087 
00088    return 0 ; /* unreachable */
00089 }

THD_fvec3 THD_mni_to_tta THD_fvec3    mv
 

Convert MNI coordinates (LPI) to TT Atlas coordinates (RAI); cf. http://www.mrc-cbu.cam.ac.uk/Imaging/mnispace.html. -------------------------------------------------------------------------

Definition at line 8 of file thd_mnicoords.c.

References LOAD_FVEC3, and THD_fvec3::xyz.

Referenced by AFNI_mnito_CB(), and THD_3mni_to_3tta().

00009 {
00010    float mx,my,mz , tx,ty,tz ;
00011    THD_fvec3 tv ;
00012 
00013    mx = mv.xyz[0] ; my = mv.xyz[1] ; mz = mv.xyz[2] ;
00014 
00015    tx = 0.99 * mx ;
00016 
00017    if( mz > 0.0 ){
00018      ty =  0.9688 * my + 0.0460 * mz ;
00019      tz = -0.0485 * my + 0.9189 * mz ;
00020    } else {
00021      ty =  0.9688 * my + 0.0420 * mz ;
00022      tz = -0.0485 * my + 0.8390 * mz ;
00023    }
00024 
00025    tx = -tx ; ty = -ty ;         /* flip x,y from LPI to RAI */
00026 
00027    LOAD_FVEC3( tv , tx,ty,tz ) ; return tv ;
00028 }

int THD_need_brick_factor THD_3dim_dataset   dset
 

set up each sub-brick *

Definition at line 872 of file thd_initdblk.c.

References THD_datablock::brick_fac, THD_3dim_dataset::dblk, DSET_BRICK_FACTOR, DSET_NVALS, ENTRY, ISVALID_DATABLOCK, ISVALID_DSET, and RETURN.

Referenced by FD_brick_to_series(), main(), THD_extract_array(), THD_extract_many_series(), and THD_insert_series().

00873 {
00874    int ii , nval ;
00875 
00876 ENTRY("THD_need_brick_factor") ;
00877 
00878    if( ! ISVALID_DSET(dset)            ) RETURN( 0 ) ;
00879    if( ! ISVALID_DATABLOCK(dset->dblk) ) RETURN( 0 ) ;
00880    if( dset->dblk->brick_fac == NULL   ) RETURN( 0 ) ;
00881 
00882    nval = DSET_NVALS(dset) ;
00883    for( ii=0 ; ii < nval ; ii++ )
00884       if( DSET_BRICK_FACTOR(dset,ii) != 0.0 &&
00885           DSET_BRICK_FACTOR(dset,ii) != 1.0   ) RETURN( 1 ) ;
00886 
00887    RETURN( 0 ) ;
00888 }

char* THD_newprefix THD_3dim_dataset   dset,
char *    suffix
 

Definition at line 9 of file thd_newprefix.c.

References DSET_PREFIX, ENTRY, ISVALID_DSET, malloc, and RETURN.

00010 {
00011    char *np ;
00012 
00013 ENTRY("THD_newprefix") ;
00014 
00015    if( !ISVALID_DSET(dset) ){
00016       np = (suffix == NULL || suffix[0] == '\0') ? strdup("none")
00017                                                  : strdup(suffix) ;
00018    } else {
00019       np = (char *) malloc( strlen(DSET_PREFIX(dset)) + strlen(suffix) + 1 ) ;
00020       strcpy(np,DSET_PREFIX(dset)) ; strcat(np,suffix) ;
00021    }
00022 
00023    RETURN(np) ;
00024 }

THD_3dim_dataset* THD_niml_to_dataset NI_group   ngr,
int    nodata
 

Make an AFNI dataset from a NIML group element.

  • The element should contain enough '<AFNI_atr ...>' elements to define the dataset header.
  • It may also contain '<VOLUME_DATA ...>' elements that contain data for the sub-bricks. This, however, is optional.
  • If the element contains a 'self_prefix' or 'AFNI_prefix' attribute, then the RHS of that will become the dataset's prefix name.
  • If the element contains a 'self_idcode' or 'AFNI_idcode' attribute, then the RHS of that will become the dataset's idcode, overriding the value that may be stored in the similar '<AFNI_atr ...>' element.
  • If this element can't easily be re-loaded (e.g., came from a socket), then the dataset should be super-locked into memory, so it won't be purged!
  • If nodata!=0 on input, then any actual sub-brick data elements in the group element will not be loaded. You'll have to call THD_add_bricks() to do that later, if desired. -------------------------------------------------------------------------

Definition at line 234 of file thd_nimlatr.c.

References ADN_none, ADN_prefix, DSET_mallocize, EDIT_dset_items(), EDIT_empty_datablock(), ENTRY, THD_3dim_dataset::idcode, MCW_IDSIZE, NI_element_type(), NI_get_attribute(), NI_GROUP_TYPE, NI_strncpy(), RETURN, MCW_idcode::str, THD_3dim_from_block(), THD_add_bricks(), THD_allow_empty_dataset(), THD_datablock_from_atr(), THD_dblkatr_from_niml(), THD_delete_datablock(), THD_update_statistics(), and THD_zerofill_dataset().

Referenced by AFNI_obj_to_dataset(), and process_NIML_AFNI_dataset().

00235 {
00236    THD_3dim_dataset *dset ;
00237    THD_datablock *blk ;
00238    char *rhs ;
00239    int ii ;
00240 
00241 ENTRY("THD_niml_to_dataset") ;
00242 
00243    if( ngr                  == NULL          ||
00244        NI_element_type(ngr) != NI_GROUP_TYPE   ) RETURN(NULL) ;
00245 
00246    /* create the shell of a dataset's datablock and populate it's attributes */
00247 
00248    blk = EDIT_empty_datablock() ;
00249 
00250    THD_dblkatr_from_niml( ngr , blk ) ;  /* load attributes from NIML */
00251 
00252    /* build the datablock from the loaded attributes */
00253 
00254    ii = THD_datablock_from_atr( blk , NULL , NULL ) ;
00255 
00256    if( ii == 0 ){                               /* bad attributes */
00257      THD_delete_datablock( blk ) ; RETURN(NULL) ;
00258    }
00259 
00260    /* build the dataset from the datablock */
00261 
00262    THD_allow_empty_dataset(1) ;
00263    dset = THD_3dim_from_block( blk ) ;
00264    THD_allow_empty_dataset(0) ;
00265    if( dset == NULL ){ THD_delete_datablock( blk ); RETURN(NULL); }
00266 
00267    DSET_mallocize(dset) ;   /* just to be sure */
00268 
00269    /* change the name of the dataset? */
00270 
00271    rhs = NI_get_attribute( ngr , "self_prefix" ) ;
00272    if( rhs == NULL )
00273      rhs = NI_get_attribute( ngr , "AFNI_prefix" ) ;  /* for the 'old' way */
00274    if( rhs != NULL )
00275      EDIT_dset_items( dset , ADN_prefix,rhs , ADN_none ) ;
00276 
00277    /* change the idcode of the dataset? */
00278 
00279    rhs = NI_get_attribute( ngr , "self_idcode" ) ;
00280    if( rhs == NULL )
00281      rhs = NI_get_attribute( ngr , "AFNI_idcode" ) ;  /* for the 'old' way */
00282    if( rhs != NULL )
00283      NI_strncpy( dset->idcode.str , rhs , MCW_IDSIZE ) ;
00284 
00285    /* now scan the group element for data elements that fill sub-bricks */
00286 
00287    if( !nodata ){
00288      (void)THD_add_bricks( dset , ngr ) ;
00289      THD_update_statistics( dset ) ;
00290    }
00291 
00292    /* 18 Mar 2005: if the header orders, zero fill any undefined bricks */
00293 
00294    rhs = NI_get_attribute( ngr , "AFNI_zerofill" ) ;
00295    if( rhs != NULL && toupper(rhs[0]) == 'Y' ) THD_zerofill_dataset(dset);
00296 
00297    RETURN(dset) ;
00298 }

NI_group* THD_nimlize_dsetatr THD_3dim_dataset   dset
 

Write all the attributes for a datablock into a set of NIML data elements, stored in a NIML group element. -----------------------------------------------------------------------

Definition at line 10 of file thd_nimlatr.c.

References THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, calloc, ATR_string::ch, THD_3dim_dataset::dblk, ENTRY, ATR_float::fl, free, THD_3dim_dataset::idcode, ATR_int::in, ISVALID_DSET, malloc, ATR_float::name, ATR_int::name, ATR_string::name, THD_datablock::natr, ATR_string::nch, ATR_float::nfl, NI_add_column(), NI_add_to_group(), NI_FLOAT, NI_INT, NI_new_data_element(), NI_new_group_element(), NI_rename_group(), NI_set_attribute(), NI_STRING, NI_TEXT_MODE, ATR_int::nin, NI_element::outmode, RETURN, MCW_idcode::str, THD_set_dataset_attributes(), THD_zblock(), ATR_any::type, and ZBLOCK.

Referenced by main(), nifti_set_afni_extension(), SUMA_SendDset_Afni(), THD_dataset_to_niml(), and THD_write_nimlatr().

00011 {
00012    THD_datablock *blk ;
00013    ATR_any *atr_any ;
00014    NI_element *nel ;
00015    int ia , ii ;
00016    NI_group *ngr = NULL ;   /* will be output */
00017 
00018 ENTRY("THD_nimlize_dsetatr") ;
00019 
00020    /*--- sanity checks ---*/
00021 
00022    if( !ISVALID_DSET(dset) ) RETURN(ngr) ;
00023    blk = dset->dblk ;
00024    if( blk == NULL )         RETURN(ngr) ;
00025 
00026    THD_set_dataset_attributes( dset ) ;
00027    if( blk->natr == 0 || blk->atr == NULL ) RETURN(ngr) ;
00028 
00029    /* create empty output group */
00030 
00031    ngr = NI_new_group_element() ;
00032 
00033    NI_rename_group( ngr , "AFNI_dataset" ) ;
00034 
00035    NI_set_attribute( ngr , "self_idcode" , dset->idcode.str ) ;
00036 
00037    /* make a data element for each attribute ... */
00038 
00039    for( ia=0 ; ia < blk->natr ; ia++ ){
00040 
00041      atr_any = &(blk->atr[ia]) ;
00042      if( atr_any == NULL ) continue ;   /* bad attribute */
00043 
00044      switch( atr_any->type ){
00045 
00046        /* numeric types are easy: a single column vector with the numbers */
00047 
00048        case ATR_FLOAT_TYPE:{
00049          ATR_float *atr_flo = (ATR_float *)atr_any ;
00050 
00051          nel = NI_new_data_element( "AFNI_atr" , atr_flo->nfl ) ;
00052          nel->outmode = NI_TEXT_MODE ;
00053          NI_set_attribute( nel , "atr_name" , atr_flo->name ) ;
00054          NI_add_column( nel , NI_FLOAT , atr_flo->fl ) ;
00055          NI_add_to_group( ngr , nel ) ;
00056        }
00057        break ;
00058 
00059        case ATR_INT_TYPE:{
00060          ATR_int *atr_int = (ATR_int *)atr_any ;
00061 
00062          nel = NI_new_data_element( "AFNI_atr" , atr_int->nin ) ;
00063          nel->outmode = NI_TEXT_MODE ;
00064          NI_set_attribute( nel , "atr_name" , atr_int->name ) ;
00065          NI_add_column( nel , NI_INT , atr_int->in ) ;
00066          NI_add_to_group( ngr , nel ) ;
00067        }
00068        break ;
00069 
00070        /* 02 Jun 2005: If string to save is too long, break it into pieces.
00071                        Will have to be reassembled on input into one string. */
00072 
00073 #undef  SZMAX
00074 #define SZMAX 1000
00075        case ATR_STRING_TYPE:{
00076          ATR_string *atr_str = (ATR_string *)atr_any ;
00077          int nnn , nstr , istr , ibot,itop ;
00078          char **sar ;
00079 
00080          nnn  = atr_str->nch ; if( nnn <= 0 ) break ;
00081          nstr = ((nnn-1)/SZMAX) + 1 ;
00082          sar  = (char **)malloc(sizeof(char *)*nstr) ;
00083          for( istr=0 ; istr < nstr ; istr++ ){
00084            ibot = istr*SZMAX ;
00085            itop = ibot+SZMAX ; if( itop > atr_str->nch ) itop = atr_str->nch ;
00086            nnn  = itop-ibot ;
00087            sar[istr] = (char *)calloc(1,nnn+1) ;
00088            memcpy( sar[istr] , atr_str->ch+ibot , nnn ) ;
00089            THD_zblock( nnn , sar[istr] ) ;
00090            sar[istr][nnn] = '\0' ;
00091          }
00092          if( nnn > 1 && sar[nstr-1][nnn-1] == ZBLOCK )
00093            sar[nstr-1][nnn-1] = '\0' ;
00094 
00095          nel = NI_new_data_element( "AFNI_atr" , nstr ) ;
00096          nel->outmode = NI_TEXT_MODE ;
00097          NI_set_attribute( nel , "atr_name" , atr_str->name ) ;
00098 
00099          NI_add_column( nel , NI_STRING , sar ) ;
00100          NI_add_to_group( ngr , nel ) ;
00101 
00102          for( istr=0 ; istr < nstr ; istr++ ) free((void *)sar[istr]) ;
00103          free((void *)sar) ;
00104        }
00105        break ;
00106 
00107      } /* end of switch on atr type */
00108 
00109    } /* end of loop over all atr's */
00110 
00111    /*--- done ---*/
00112 
00113    RETURN(ngr) ;
00114 }

void THD_normalize int   ,
float *   
 

Definition at line 181 of file thd_detrend.c.

References far.

Referenced by main().

00182 {
00183    register int ii ;
00184    register float fac ;
00185 
00186    if( npt <= 0 || far == NULL ) return ;
00187 
00188    fac = 0 ;
00189    for( ii=0 ; ii < npt ; ii++ ) fac += far[ii]*far[ii] ;
00190    if( fac == 0.0 ) return ;
00191    fac = 1.0 / sqrt(fac) ;
00192    for( ii=0 ; ii < npt ; ii++ ) far[ii] /= fac ;
00193    return ;
00194 }

THD_string_array* THD_normalize_flist THD_string_array  
 

Definition at line 260 of file thd_sarr.c.

References ADDTO_SARR, AFNI_yesenv(), THD_string_array::ar, DESTROY_SARR, INIT_SARR, THD_string_array::num, REMOVEFROM_SARR, SARR_lookfor_string(), and THD_equiv_files().

Referenced by AFNI_read_inputs().

00261 {
00262    THD_string_array * star_out , * star_qqq ;
00263    static char rpath[2048] ;
00264    char * rp ;
00265    int ii , jj , nleft , skip_realpath=0 ;
00266 
00267    if( star_in == NULL || star_in->num <= 0 ) return NULL ;
00268 
00269    skip_realpath = AFNI_yesenv("AFNI_NOREALPATH") ;
00270 
00271    INIT_SARR(star_out) ;
00272 
00273    for( ii=0 ; ii < star_in->num ; ii++ ){
00274       if( skip_realpath ) rp = star_in->ar[ii] ;
00275       else                rp = realpath( star_in->ar[ii] , rpath ) ;
00276 
00277       if( rp != NULL ) ADDTO_SARR( star_out , rp ) ;
00278    }
00279 
00280    if( star_out->num == 0 ){ DESTROY_SARR(star_out) ; return NULL ; }
00281 
00282    nleft = 0 ;
00283    for( ii=0 ; ii < star_out->num ; ii++ ){
00284       rp = star_out->ar[ii] ;
00285       if( rp != NULL ){
00286          nleft++ ; jj = ii ;
00287          while( jj >= 0 ){
00288             jj = SARR_lookfor_string( star_out , rp , jj+1 ) ;
00289             if( jj >= 0 ) REMOVEFROM_SARR(star_out,jj) ;
00290          }
00291 
00292          for( jj=ii+1 ; jj < star_out->num ; jj++ ){
00293             if( THD_equiv_files(rp,star_out->ar[jj]) )
00294                REMOVEFROM_SARR(star_out,jj) ;
00295          }
00296       }
00297    }
00298 
00299    if( nleft == 0 ){ DESTROY_SARR(star_out) ; return NULL ; }
00300 
00301    if( nleft == star_out->num ) return star_out ;
00302 
00303    INIT_SARR(star_qqq) ;
00304    for( ii=0 ; ii < star_out->num ; ii++ ){
00305       rp = star_out->ar[ii] ;
00306       if( rp != NULL ) ADDTO_SARR(star_qqq,rp) ;
00307    }
00308 
00309 #if 0
00310 fprintf(stderr,"\nTHD_normalize_flist: in=%d out=%d qqq=%d\n",
00311         star_in->num , star_out->num , star_qqq->num ) ;
00312 #endif
00313 
00314    DESTROY_SARR(star_out) ; return star_qqq ;
00315 }

THD_3dim_dataset* THD_open_1D char *    pathname
 

Open a 1D file as an AFNI dataset. Each column is a separate sub-brick. Ignore comments at this time. Data is not loaded into bricks. -------------------------------------------------------------------

Definition at line 13 of file thd_1Ddset.c.

References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ADN_type, ADN_xyzdel, ADN_xyzorg, AFNI_yesenv(), ANAT_BUCK_TYPE, ANAT_EPI_TYPE, THD_diskptr::brick_name, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, THD_datablock::diskptr, dt, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, flip(), free, getenv(), HEAD_ANAT_TYPE, THD_3dim_dataset::idcode, THD_ivec3::ijk, MCW_hash_idcode(), MCW_strncpy, mri_free(), mri_read_1D(), mri_transpose(), MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, STORAGE_BY_1D, THD_diskptr::storage_mode, MCW_idcode::str, strtod(), THD_MAX_PREFIX, THD_open_3D(), THD_trailname(), UNITS_SEC_TYPE, and THD_fvec3::xyz.

Referenced by THD_open_dataset(), and THD_open_one_dataset().

00014 {
00015    THD_3dim_dataset *dset=NULL ;
00016    MRI_IMAGE *flim ;
00017    char prefix[1024] , *ppp , tname[12] , *pn ;
00018    THD_ivec3 nxyz ;
00019    THD_fvec3 dxyz , orgxyz ;
00020    int nvals , lpn , flip=0 ;
00021    FILE *fp ;
00022 
00023 ENTRY("THD_open_1D") ;
00024 
00025    /*-- open input file --*/
00026 
00027    if( pathname == NULL || pathname[0] == '\0' ) RETURN(NULL);
00028 
00029    /*-- check if it is a NIML-ish AFNI dataset;
00030         if so, read it in that way instead of the 1D way [21 Mar 2003] --*/
00031 
00032    if( strchr(pathname,'[') == NULL &&
00033        strchr(pathname,'{') == NULL && strchr(pathname,'\'') == NULL ){
00034 
00035      pn = strdup(pathname) ; fp = fopen(pn,"r") ;
00036 
00037      if( fp == NULL ){
00038        char *p1 = strstr(pn,"1D") ;   /* if can't open .1D, try .3D */
00039        if( p1 != NULL ){
00040          *p1 = '3' ; fp = fopen(pn,"r") ;
00041        }
00042        if( fp == NULL ){
00043          fprintf(stderr,"** THD_open_1D(%s): can't open file\n",pathname);
00044          free(pn); RETURN(NULL);
00045        }
00046      }
00047      memset(prefix,0,133) ; fread(prefix,1,128,fp) ; fclose(fp) ;
00048      if( strstr(prefix,"<AFNI_") != NULL && strstr(prefix,"dataset") != NULL ){
00049        dset = THD_open_3D(pn) ;
00050        if( dset != NULL && strcmp(pathname,pn) != 0 )
00051          fprintf(stderr,"** THD_open_1D(%s): substituted %s\n",pathname,pn) ;
00052        free(pn) ; return dset ;
00053      }
00054    }
00055 
00056    /*-- otherwise, read it into an MRI_IMAGE, then mangle image into dataset --*/
00057 
00058    lpn = strlen(pathname) ; pn = strdup(pathname) ;
00059 
00060    flip = (pn[lpn-1] == '\'') ;     /* 12 Jul 2005: allow for tranposing input */
00061    if( flip ) pn[lpn-1] = '\0' ;
00062 
00063    flim = mri_read_1D(pn) ;
00064    if( flim == NULL ){
00065      fprintf(stderr,"** Can't read 1D dataset file %s\n",pn); free(pn); RETURN(NULL);
00066    }
00067    if( flip ){
00068      MRI_IMAGE *qim = mri_transpose(flim); mri_free(flim); flim = qim;
00069    }
00070 
00071    /*-- make a dataset --*/
00072 
00073    dset = EDIT_empty_copy(NULL) ;        /* default (useless) dataset */
00074 
00075    ppp  = THD_trailname(pn,0) ;                   /* strip directory */
00076    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;  /* to make prefix */
00077    ppp  = strchr( prefix , '[' ) ;
00078    if( ppp != NULL ) *ppp = '\0' ;
00079 
00080    nxyz.ijk[0] = flim->nx ; dxyz.xyz[0] = 1.0 ;    /* setup axes */
00081    nxyz.ijk[1] = 1        ; dxyz.xyz[1] = 1.0 ;
00082    nxyz.ijk[2] = 1        ; dxyz.xyz[2] = 1.0 ;
00083 
00084    orgxyz.xyz[0] = 0.0 ;                           /* arbitrary origin */
00085    orgxyz.xyz[1] = 0.0 ;
00086    orgxyz.xyz[2] = 0.0 ;
00087 
00088    nvals = flim->ny ;                              /* number of sub-bricks */
00089 
00090    MCW_hash_idcode( pathname , dset ) ; /* 06 May 2005 */
00091    dset->idcode.str[0] = 'A' ;          /* overwrite 1st 3 bytes of IDcode */
00092    dset->idcode.str[1] = '1' ;
00093    dset->idcode.str[2] = 'D' ;
00094 
00095    /* note we accept default orientation (RAI) here
00096       (no use of ADN_xyzorient), since we actually
00097       don't have any spatial structure to speak of */
00098 
00099    EDIT_dset_items( dset ,
00100                       ADN_prefix      , prefix ,
00101                       ADN_datum_all   , MRI_float ,
00102                       ADN_nxyz        , nxyz ,
00103                       ADN_xyzdel      , dxyz ,
00104                       ADN_xyzorg      , orgxyz ,
00105                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00106                       ADN_nvals       , nvals ,
00107                       ADN_type        , HEAD_ANAT_TYPE ,
00108                       ADN_func_type   , ANAT_BUCK_TYPE ,
00109                     ADN_none ) ;
00110 
00111    if( nvals > 1 && AFNI_yesenv("AFNI_1D_TIME") ){ /* pretend it is 3D+time */
00112      char *eee = getenv("AFNI_1D_TIME_TR") ;
00113      float dt = 0.0 ;
00114      if( eee != NULL ) dt = strtod(eee,NULL) ;
00115      if( dt <= 0.0   ) dt = 1.0 ;
00116      EDIT_dset_items( dset ,
00117                         ADN_func_type, ANAT_EPI_TYPE ,
00118                         ADN_ntt      , nvals ,
00119                         ADN_ttorg    , 0.0 ,
00120                         ADN_ttdel    , dt ,    /* TR */
00121                         ADN_ttdur    , 0.0 ,
00122                         ADN_tunits   , UNITS_SEC_TYPE ,
00123                       ADN_none ) ;
00124    }
00125 
00126    dset->dblk->diskptr->storage_mode = STORAGE_BY_1D ;
00127    strcpy( dset->dblk->diskptr->brick_name , pathname ) ;
00128 
00129    /*-- purge image data and return the empty dataset */
00130 
00131    mri_free(flim) ; free(pn) ; RETURN(dset) ;
00132 }

THD_3dim_dataset* THD_open_3D char *    pathname
 

Open a NIML 3D file as an AFNI dataset. Each column is a separate sub-brick. Dataset returned is empty (no data). -------------------------------------------------------------------

Definition at line 13 of file thd_3Ddset.c.

References ADN_datum_array, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_ttdel, ADN_tunits, ADN_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, AFNI_FIRST_STATCODE, AFNI_LAST_STATCODE, ANAT_BUCK_TYPE, ANAT_EPI_TYPE, THD_diskptr::brick_name, calloc, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, THD_datablock::diskptr, dt, EDIT_dset_items(), EDIT_empty_copy(), EDIT_STATAUX4, ENTRY, free, HEAD_ANAT_TYPE, THD_3dim_dataset::idcode, THD_ivec3::ijk, MCW_hash_idcode(), MCW_IDSIZE, MIN, NI_element::name, NI_decode_string_list(), NI_delete_str_array, NI_element_type(), NI_ELEMENT_TYPE, NI_free_element(), NI_get_attribute(), NI_IS_NUMERIC_TYPE, NI_read_element(), NI_read_header_only(), NI_skip_procins(), NI_stat_distname(), NI_STAT_FIRSTCODE, NI_STAT_LASTCODE, NI_stat_numparam(), NI_stream_close(), NI_stream_open(), NI_strncpy(), NI_str_array::num, OR3OK, ORCODE, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_R2L_TYPE, RETURN, STATUS, STORAGE_BY_3D, THD_diskptr::storage_mode, MCW_idcode::str, NI_str_array::str, strtod(), THD_MAX_NAME, THD_MAX_PREFIX, THD_trailname(), UNITS_SEC_TYPE, NI_element::vec_axis_delta, NI_element::vec_axis_label, NI_element::vec_axis_len, NI_element::vec_axis_origin, NI_element::vec_len, NI_element::vec_num, NI_element::vec_rank, NI_element::vec_typ, and THD_fvec3::xyz.

Referenced by THD_open_1D(), and THD_open_one_dataset().

00014 {
00015    THD_3dim_dataset *dset=NULL ;
00016    char prefix[1024] , *ppp ;
00017    THD_ivec3 nxyz , orixyz ;
00018    THD_fvec3 dxyz , orgxyz ;
00019    int nvals , ii ;
00020    NI_element *nel ;
00021    NI_stream ns ;
00022 
00023 ENTRY("THD_open_3D") ;
00024 
00025    /*-- read input file into NI_element --*/
00026 
00027    if( pathname == NULL || *pathname == '\0' ) RETURN(NULL) ;
00028 
00029    ppp = (char*)calloc( sizeof(char) , strlen(pathname)+16 ) ;
00030 
00031    strcpy(ppp,"file:") ; strcat(ppp,pathname) ;
00032    ns = NI_stream_open( ppp , "r" ) ; free(ppp) ;
00033    if( ns == NULL ) RETURN(NULL) ;
00034 
00035 STATUS("reading header") ;
00036 
00037    NI_skip_procins(1) ; NI_read_header_only(1) ;
00038    nel = NI_read_element(ns,333); NI_stream_close(ns);
00039    NI_skip_procins(0) ; NI_read_header_only(0) ;
00040 
00041    /*-- check data element for reasonability --*/
00042 
00043    if( nel == NULL                               ||   /* bad read */
00044        NI_element_type(nel) != NI_ELEMENT_TYPE   ||   /* bad element */
00045        nel->vec_num <= 0                         ||   /* no data */
00046        nel->vec_len <= 0                         ||   /* no data */
00047        strcmp(nel->name,"AFNI_3D_dataset") != 0  ||   /* incorrect data */
00048        nel->vec_rank > 3                           ){ /* weird header */
00049 
00050      fprintf(stderr,"** Can't read 3D head from %s\n",pathname) ;
00051      NI_free_element(nel) ; RETURN(NULL) ;
00052    }
00053 
00054 STATUS("checking header") ;
00055 
00056    /*-- check column types to make sure they are all numeric --*/
00057    /*   [AFNI doesn't like String or compound type datasets]   */
00058 
00059    for( ii=0 ; ii < nel->vec_num ; ii++ ){
00060 
00061      if( !NI_IS_NUMERIC_TYPE(nel->vec_typ[ii]) ){
00062        fprintf(stderr,"** 3D file %s isn't numeric!\n",pathname) ;
00063        NI_free_element(nel) ; RETURN(NULL) ;
00064      }
00065    }
00066 
00067    /*-- now have good data element ==> make a dataset --*/
00068 
00069 STATUS("making dataset") ;
00070 
00071    dset = EDIT_empty_copy(NULL) ;  /* default dataset */
00072 
00073    /* set prefix from input filename */
00074 
00075 STATUS("setting prefix") ;
00076 
00077    ppp = THD_trailname(pathname,0) ;              /* strip directory */
00078    NI_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;  /* to make prefix */
00079 
00080    /* set grid sizes from element header */
00081 
00082 STATUS("setting grid sizes") ;
00083 
00084    nxyz.ijk[0] = nel->vec_len ; nxyz.ijk[1] = nxyz.ijk[2] = 1 ;
00085    if( nel->vec_axis_len != NULL ){
00086      if( nel->vec_rank >= 1 ) nxyz.ijk[0] = nel->vec_axis_len[0] ;
00087      if( nel->vec_rank >= 2 ) nxyz.ijk[1] = nel->vec_axis_len[1] ;
00088      if( nel->vec_rank >= 3 ) nxyz.ijk[2] = nel->vec_axis_len[2] ;
00089    }
00090 
00091    /* set grid spacings */
00092 
00093 STATUS("setting grid spacings") ;
00094 
00095    dxyz.xyz[0] = dxyz.xyz[1] = dxyz.xyz[2] = 1.0 ;
00096    if( nel->vec_axis_delta != NULL ){
00097      if( nel->vec_rank >= 1) dxyz.xyz[0] = nel->vec_axis_delta[0] ;
00098      if( nel->vec_rank >= 2) dxyz.xyz[1] = nel->vec_axis_delta[1] ;
00099      if( nel->vec_rank >= 3) dxyz.xyz[2] = nel->vec_axis_delta[2] ;
00100    }
00101 
00102    /* set grid origins */
00103 
00104 STATUS("setting grid origins") ;
00105 
00106    orgxyz.xyz[0] = orgxyz.xyz[1] = orgxyz.xyz[2] = 0.0 ;
00107    if( nel->vec_axis_origin != NULL ){
00108      if( nel->vec_rank >= 1) orgxyz.xyz[0] = nel->vec_axis_origin[0] ;
00109      if( nel->vec_rank >= 2) orgxyz.xyz[1] = nel->vec_axis_origin[1] ;
00110      if( nel->vec_rank >= 3) orgxyz.xyz[2] = nel->vec_axis_origin[2] ;
00111    }
00112 
00113    /* set grid orientations (default is RAI) */
00114 
00115 STATUS("setting grid orientation") ;
00116 
00117    { char orcx='R', orcy='A', orcz='I' ;
00118      int oxx,oyy,ozz ;
00119      if( nel->vec_rank == 3 && nel->vec_axis_label != NULL ){
00120        orcx = toupper(nel->vec_axis_label[0][0]) ;
00121        orcy = toupper(nel->vec_axis_label[1][0]) ;
00122        orcz = toupper(nel->vec_axis_label[2][0]) ;
00123      }
00124      oxx = ORCODE(orcx); oyy = ORCODE(orcy); ozz = ORCODE(orcz);
00125      if( !OR3OK(oxx,oyy,ozz) ){
00126        oxx = ORI_R2L_TYPE; oyy = ORI_A2P_TYPE; ozz = ORI_I2S_TYPE;
00127      }
00128 
00129      orixyz.ijk[0] = oxx ; orixyz.ijk[1] = oyy ; orixyz.ijk[2] = ozz ;
00130    }
00131 
00132    /* number of sub-bricks (one per vector/column) */
00133 
00134    nvals = nel->vec_num ;
00135 
00136    /* set idcode from element, or take random default one */
00137 
00138 STATUS("setting idcode") ;
00139 
00140    ppp = NI_get_attribute( nel , "self_idcode" ) ;
00141    if( ppp == NULL )
00142      ppp = NI_get_attribute( nel , "ni_idcode" ) ;
00143    if( ppp != NULL && *ppp != '\0' ){
00144      NI_strncpy( dset->idcode.str , ppp , MCW_IDSIZE ) ;
00145    } else {
00146      MCW_hash_idcode( pathname , dset ) ; /* 06 May 2005 */
00147      dset->idcode.str[0] = 'A' ;          /* overwrite 1st 3 bytes of idcode */
00148      dset->idcode.str[1] = '3' ;
00149      dset->idcode.str[2] = 'D' ;
00150    }
00151 
00152    /*-- now modify the default dataset --*/
00153 
00154 STATUS("Editing dataset") ;
00155 
00156    EDIT_dset_items( dset ,
00157                       ADN_prefix      , prefix ,
00158                       ADN_datum_array , nel->vec_typ ,
00159                       ADN_nxyz        , nxyz ,
00160                       ADN_xyzdel      , dxyz ,
00161                       ADN_xyzorg      , orgxyz ,
00162                       ADN_xyzorient   , orixyz ,
00163                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00164                       ADN_nvals       , nvals ,
00165                       ADN_type        , HEAD_ANAT_TYPE ,
00166                       ADN_func_type   , ANAT_BUCK_TYPE ,
00167                     ADN_none ) ;
00168 
00169    dset->dblk->diskptr->storage_mode = STORAGE_BY_3D ;
00170    NI_strncpy( dset->dblk->diskptr->brick_name , pathname , THD_MAX_NAME ) ;
00171 
00172    /*-- time axis? [03 Jun 2005] --*/
00173 
00174    ppp = NI_get_attribute( nel , "ni_timestep" ) ;
00175    if( ppp != NULL && nvals > 1 ){
00176      float dt = strtod(ppp,NULL) ; if( dt <= 0.0 ) dt = 1.0 ;
00177      EDIT_dset_items( dset ,
00178                         ADN_func_type , ANAT_EPI_TYPE ,
00179                         ADN_ntt       , nvals ,
00180                         ADN_ttdel     , dt ,
00181                         ADN_tunits    , UNITS_SEC_TYPE ,
00182                       ADN_none ) ;
00183    }
00184 
00185 STATUS("checking for statistics") ;
00186 
00187    /*-- see if we have any statistics bricks --*/
00188 
00189    ppp = NI_get_attribute( nel , "ni_stat" ) ;
00190    if( ppp != NULL ){
00191      NI_str_array *sar = NI_decode_string_list( ppp , ";" ) ;
00192      if( sar != NULL ){
00193        int itop=MIN(sar->num,nvals) , jj,ll ;
00194        char *dnam , qnam[64] ;
00195        for( ii=0 ; ii < itop ; ii++ ){
00196          if( strcmp(sar->str[ii],"none") == 0 ) continue ;
00197          for( jj=NI_STAT_FIRSTCODE ; jj <= NI_STAT_LASTCODE ; jj++ ){
00198            dnam = NI_stat_distname(jj) ;
00199            strcpy(qnam,dnam); strcat(qnam,"("); ll = strlen(qnam);
00200            if( strncmp(sar->str[ii],qnam,ll) == 0 ) break ;
00201          }
00202          if( jj >= AFNI_FIRST_STATCODE && jj <= AFNI_LAST_STATCODE ){
00203            float parm[4]={1,1,1,1} ; int np,kk,mm , sp ;
00204            np = NI_stat_numparam(jj) ; sp = ll ;
00205            for( kk=0 ; kk < np ; kk++ ){
00206              mm = 0 ; sscanf(sar->str[ii]+sp,"%f%n",parm+kk,&mm) ; sp += mm+1 ;
00207            }
00208            EDIT_STATAUX4( dset , ii , jj , parm[0],parm[1],parm[2],parm[3] ) ;
00209          }
00210        }
00211        NI_delete_str_array(sar) ;
00212      }
00213    }
00214 
00215    /*-- purge the NIML data element and return the new dataset --*/
00216 
00217 STATUS("freeing element") ;
00218 
00219    NI_free_element( nel ) ;
00220    RETURN(dset) ;
00221 }

THD_3dim_dataset* THD_open_analyze char *    hname
 

Open an ANALYZE .hdr file as an unpopulated AFNI dataset. It will be populated from the .img file, in THD_load_analyze(). -------------------------------------------------------------------

Definition at line 107 of file thd_analyzeread.c.

References ADN_brick_fac, ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, AFMALL, AFNI_noenv(), AFNI_yesenv(), ANAT_EPI_TYPE, ANAT_MRAN_TYPE, ANDT_COMPLEX, ANDT_FLOAT, ANDT_RGB, ANDT_SIGNED_INT, ANDT_SIGNED_SHORT, ANDT_string, ANDT_UNSIGNED_CHAR, THD_diskptr::brick_name, THD_diskptr::byte_order, DATABLOCK_MEM_MALLOC, image_dimension::datatype, THD_3dim_dataset::dblk, image_dimension::dim, dsr::dime, THD_datablock::diskptr, dt, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, free, FUNC_FIM_TYPE, image_dimension::funused1, getenv(), HEAD_ANAT_TYPE, HEAD_FUNC_TYPE, dsr::hist, THD_3dim_dataset::idcode, THD_ivec3::ijk, MCW_hash_idcode(), MCW_strncpy, mri_datum_size(), mri_short_order(), nz, OR3OK, ORCODE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, data_history::originator, image_dimension::pixdim, RETURN, REVERSE_ORDER, STORAGE_BY_ANALYZE, THD_diskptr::storage_mode, MCW_idcode::str, swap_2(), swap_analyze_hdr(), THD_filesize(), thd_floatscan(), THD_MAX_NAME, THD_MAX_PREFIX, THD_open_nifti(), THD_trailname(), UNITS_SEC_TYPE, VIEW_ORIGINAL_TYPE, VIEW_TALAIRACH_TYPE, and THD_fvec3::xyz.

Referenced by THD_init_session(), and THD_open_one_dataset().

00108 {
00109    FILE * fp ;
00110    char iname[THD_MAX_NAME] ;
00111    int ii , doswap ;
00112    struct dsr hdr ;    /* ANALYZE .hdr format */
00113    int ngood , length , datum_type , datum_len ;
00114    int   nx,ny,nz,nt ;
00115    float dx,dy,dz,dt ;
00116    float fac=0.0 ;     /* brick scaling factor */
00117 
00118    THD_3dim_dataset *dset=NULL ;
00119    char prefix[THD_MAX_PREFIX] , *ppp ;
00120    THD_ivec3 nxyz , orixyz ;
00121    THD_fvec3 dxyz , orgxyz ;
00122    int iview ;
00123    short spmorg , spmxx,spmyy,spmzz ;  /* 03 Nov 2003 */
00124 
00125 ENTRY("THD_open_analyze") ;
00126 
00127    /* 28 Aug 2003: check if this is a NIFTI file instead */
00128 
00129    { nifti_image *nim = nifti_image_read(hname,0) ;
00130      if( nim != NULL && nim->nifti_type > 0 ){
00131        nifti_image_free(nim); dset = THD_open_nifti(hname); RETURN(dset);
00132      }
00133    }
00134 
00135    /*-- check & prepare filenames --*/
00136 
00137    if( hname == NULL ) RETURN( NULL );
00138    ii = strlen(hname) ; if( ii < 5 ) RETURN( NULL );
00139    if( strcmp(hname+ii-4,".hdr") != 0 ) RETURN( NULL );
00140    strcpy(iname,hname) ; strcpy(iname+ii-3,"img") ;  /* .img filename */
00141 
00142    /*-- read .hdr file into struct --*/
00143 
00144    fp = fopen( hname , "rb" ) ;
00145    if( fp == NULL ) RETURN( NULL );
00146    hdr.dime.dim[0] = 0 ;
00147    fread( &hdr , 1 , sizeof(struct dsr) , fp ) ;
00148    fclose(fp) ;
00149    if( hdr.dime.dim[0] == 0 ){    /* bad input */
00150      fprintf(stderr,"*** ANALYZE file %s has dim[0]=0!\n",hname) ;
00151      RETURN( NULL ) ;
00152    }
00153 
00154    /*-- check .img file for existence and size --*/
00155 
00156    length = THD_filesize(iname) ;  /* will use this later */
00157    if( length <= 0 ){
00158      fprintf(stderr,"*** Can't find ANALYZE file %s\n",iname) ;
00159      RETURN( NULL );
00160    }
00161 
00162    /*-- check for swap-age of header --*/
00163 
00164    doswap = (hdr.dime.dim[0] < 0 || hdr.dime.dim[0] > 15) ;
00165    if( doswap ) swap_analyze_hdr( &hdr ) ;
00166 
00167    /*-- get a scale factor for images --*/
00168 
00169    if( !AFNI_noenv("AFNI_ANALYZE_SCALE") ){
00170      fac = hdr.dime.funused1 ;
00171      (void) thd_floatscan( 1 , &fac ) ;
00172      if( fac < 0.0 || fac == 1.0 ) fac = 0.0 ;
00173    }
00174 
00175    /*-- get data type for each voxel --*/
00176 
00177    switch( hdr.dime.datatype ){
00178      default:
00179         fprintf(stderr,"*** %s: Unsupported ANALYZE datatype=%d (%s)\n",
00180                 hname,hdr.dime.datatype,ANDT_string(hdr.dime.datatype) ) ;
00181      RETURN( NULL );
00182 
00183      case ANDT_UNSIGNED_CHAR: datum_type = MRI_byte   ; break;
00184      case ANDT_SIGNED_SHORT:  datum_type = MRI_short  ; break;
00185      case ANDT_FLOAT:         datum_type = MRI_float  ; break;
00186      case ANDT_COMPLEX:       datum_type = MRI_complex; break;
00187      case ANDT_RGB:           datum_type = MRI_rgb    ; break;
00188 #if 0
00189      case ANDT_SIGNED_INT:    datum_type = MRI_int    ; break; /* not in AFNI */
00190 #endif
00191    }
00192 
00193    datum_len = mri_datum_size(datum_type) ;  /* number bytes per voxel */
00194 
00195    /*-- compute dimensions of images, and number of images --*/
00196 
00197    nx = hdr.dime.dim[1] ;
00198    ny = hdr.dime.dim[2] ;
00199    if( nx < 2 || ny < 2 ) RETURN( NULL );
00200 
00201    switch( hdr.dime.dim[0] ){
00202      case 2:  nz = 1 ; nt = 1 ;                           ; break ;
00203      case 3:  nz = hdr.dime.dim[3] ; nt = 1 ;             ; break ;
00204      case 4:  nz = hdr.dime.dim[3] ; nt = hdr.dime.dim[4] ; break ;
00205 
00206      default:
00207        fprintf(stderr,"*** ANALYZE file %s has %d dimensions!\n",
00208                hname,hdr.dime.dim[0]) ;
00209        RETURN( NULL ) ;
00210    }
00211    if( nz < 1 ) nz = 1 ;
00212    if( nt < 1 ) nt = 1 ;
00213 
00214    /*-- voxel sizes --*/
00215 
00216    dx = fabs(hdr.dime.pixdim[1]) ; if( dx == 0.0 )            dx = 1.0 ;
00217    dy = fabs(hdr.dime.pixdim[2]) ; if( dy == 0.0 )            dy = 1.0 ;
00218    dz = fabs(hdr.dime.pixdim[3]) ; if( dz == 0.0 )            dz = 1.0 ;
00219    dt = fabs(hdr.dime.pixdim[4]) ; if( dt == 0.0 || nt == 1 ) dt = 1.0 ;
00220 
00221    ngood = datum_len*nx*ny*nz*nt ;  /* number bytes needed in .img file */
00222    if( length < ngood ){
00223      fprintf( stderr,
00224        "*** ANALYZE file %s is %d bytes long but must be %d bytes long\n"
00225        "*** for nx=%d ny=%d nz=%d nt=%d and %d bytes/voxel\n",
00226        iname,length,ngood,nx,ny,nz,nt,datum_len ) ;
00227      fclose(fp) ; RETURN( NULL );
00228    }
00229 
00230    /* check SPM originator field - 03 Nov 2003 */
00231    /* 11 Mar 2004 - oops: SPM indexes start at 1 - RWCox */
00232 
00233    spmorg = spmxx = spmyy = spmzz = 0 ;
00234    { short xyzuv[5] , xx,yy,zz ;
00235      memcpy( xyzuv , hdr.hist.originator , 10 ) ;
00236      if( xyzuv[3] == 0 && xyzuv[4] == 0 ){
00237        xx = xyzuv[0] ; yy = xyzuv[1] ; zz = xyzuv[2] ;
00238        if( doswap ){ swap_2(&xx); swap_2(&yy); swap_2(&zz); }
00239        if( xx > 0 && xx < nx-1 &&
00240            yy > 0 && yy < ny-1 &&
00241            zz > 0 && zz < nz-1   ){ spmorg=1; spmxx=xx-1; spmyy=yy-1; spmzz=zz-1; }
00242      }
00243    }
00244 
00245    /*-- make a dataset --*/
00246 
00247    dset = EDIT_empty_copy(NULL) ;
00248 
00249    dset->idcode.str[0] = 'A' ;  /* overwrite 1st 3 bytes */
00250    dset->idcode.str[1] = 'N' ;
00251    dset->idcode.str[2] = 'Z' ;
00252 
00253    MCW_hash_idcode( hname , dset ) ;  /* 06 May 2005 */
00254 
00255    ppp = THD_trailname(hname,0) ;                   /* strip directory */
00256    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;   /* to make prefix */
00257 
00258    nxyz.ijk[0] = nx ; dxyz.xyz[0] = dx ;  /* setup axes lengths and voxel sizes */
00259    nxyz.ijk[1] = ny ; dxyz.xyz[1] = dy ;
00260    nxyz.ijk[2] = nz ; dxyz.xyz[2] = dz ;
00261 
00262    /*-- default orientation is LPI, but user can alter via environment --*/
00263 
00264    { char *ori = getenv("AFNI_ANALYZE_ORIENT") ;
00265      int oxx,oyy,ozz ;
00266      if( ori == NULL || strlen(ori) < 3 ) ori = "LPI"; /* set default LPI */
00267 
00268      oxx = ORCODE(ori[0]); oyy = ORCODE(ori[1]); ozz = ORCODE(ori[2]);
00269      if( !OR3OK(oxx,oyy,ozz) ){
00270        oxx = ORI_L2R_TYPE; oyy = ORI_P2A_TYPE; ozz = ORI_I2S_TYPE; /* LPI? */
00271      }
00272 
00273      orixyz.ijk[0] = oxx ;
00274      orixyz.ijk[1] = oyy ;
00275      orixyz.ijk[2] = ozz ;
00276    }
00277 
00278    /*-- origin of coordinates --*/
00279 
00280    orgxyz.xyz[0] = 0.5*dx ;  /* FSL:  (0,0,0) is at outer corner of 1st voxel */
00281    orgxyz.xyz[1] = 0.5*dy ;  /* AFNI: these are coords of center of 1st voxel */
00282    orgxyz.xyz[2] = 0.5*dz ;
00283 
00284    /*-- 04 Oct 2002: allow auto-centering of ANALYZE datasets --*/
00285 
00286    if( AFNI_yesenv("AFNI_ANALYZE_AUTOCENTER") ){
00287      orgxyz.xyz[0] = -0.5 * (nx-1) * dx ;
00288      orgxyz.xyz[1] = -0.5 * (ny-1) * dy ;
00289      orgxyz.xyz[2] = -0.5 * (nz-1) * dz ;
00290    }
00291 
00292    
00293    iview = VIEW_ORIGINAL_TYPE ;   /* can't tell if it is Talairach-ed (default)*/
00294    {/* ZSS Dec 15 03 */
00295       char *vie = getenv("AFNI_ANALYZE_VIEW") ;
00296       if (!vie) iview = VIEW_ORIGINAL_TYPE; 
00297       else {
00298          if (strcmp(vie, "tlrc") == 0) iview = VIEW_TALAIRACH_TYPE; 
00299          else if (strcmp(vie, "orig") == 0) iview = VIEW_ORIGINAL_TYPE;
00300          else {
00301             fprintf (stderr,  "\nWarning: Bad value (%s) for environment \n"
00302                               "variable AFNI_ANALYZE_VIEW. Choose from:\n"
00303                               "orig or tlrc.\n"
00304                               "Assuming orig view.\n", vie);
00305             iview = VIEW_ORIGINAL_TYPE;  
00306          }
00307       }
00308    }
00309    
00310    if( AFNI_yesenv("AFNI_ANALYZE_ORIGINATOR") && spmorg ){  /* 03 Nov 2003 */
00311      if ( !getenv ("AFNI_ANALYZE_VIEW") ) { /* ZSS Dec. 16 03 */
00312        iview         = VIEW_TALAIRACH_TYPE ;     /* for backward compatibility */
00313      } 
00314      orgxyz.xyz[0] = -spmxx * dx ; /* (0,0,0) is at (spmxx,spmyy,spmzz) */
00315      orgxyz.xyz[1] = -spmyy * dy ;
00316      orgxyz.xyz[2] = -spmzz * dz ;
00317    }
00318 
00319    /* 10 Oct 2002: change voxel size signs, if axis orientation is negative */
00320    /*              [above, we assumed that axes were oriented in - to + way] */
00321 
00322    if( ORIENT_sign[orixyz.ijk[0]] == '-' ){
00323      dxyz.xyz[0]   = -dxyz.xyz[0]   ;
00324      orgxyz.xyz[0] = -orgxyz.xyz[0] ;
00325    }
00326 
00327    if( ORIENT_sign[orixyz.ijk[1]] == '-' ){
00328      dxyz.xyz[1]   = -dxyz.xyz[1]   ;
00329      orgxyz.xyz[1] = -orgxyz.xyz[1] ;
00330    }
00331 
00332    if( ORIENT_sign[orixyz.ijk[2]] == '-' ){
00333      dxyz.xyz[2]   = -dxyz.xyz[2]   ;
00334      orgxyz.xyz[2] = -orgxyz.xyz[2] ;
00335    }
00336 
00337    /*-- actually send the values above into the dataset header --*/
00338 
00339    EDIT_dset_items( dset ,
00340                       ADN_prefix      , prefix ,
00341                       ADN_datum_all   , datum_type ,
00342                       ADN_nxyz        , nxyz ,
00343                       ADN_xyzdel      , dxyz ,
00344                       ADN_xyzorg      , orgxyz ,
00345                       ADN_xyzorient   , orixyz ,
00346                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00347                       ADN_nvals       , nt ,
00348                       ADN_type        , HEAD_ANAT_TYPE ,
00349                       ADN_view_type   , iview ,
00350                       ADN_func_type   , ANAT_MRAN_TYPE ,
00351                     ADN_none ) ;
00352 
00353    if( nt > 1 )              /** pretend it is 3D+time **/
00354       EDIT_dset_items( dset ,
00355                          ADN_func_type, ANAT_EPI_TYPE ,
00356                          ADN_ntt      , nt ,
00357                          ADN_ttorg    , 0.0 ,
00358                          ADN_ttdel    , dt ,
00359                          ADN_ttdur    , 0.0 ,
00360                          ADN_tunits   , UNITS_SEC_TYPE ,
00361                        ADN_none ) ;
00362 
00363    /* make it a func if is is a FSL special name */
00364 
00365 #ifdef ALLOW_FSL_FEAT
00366    if( strstr(prefix,"stat") != NULL )
00367      EDIT_dset_items( dset ,
00368                         ADN_type      , HEAD_FUNC_TYPE ,
00369                         ADN_func_type , FUNC_FIM_TYPE ,
00370                       ADN_none ) ;
00371 #endif
00372 
00373    /*-- set brick factors (all the same) --*/
00374 
00375    if( fac > 0.0 ){
00376      float *bf = AFMALL(float, sizeof(float)*nt) ;
00377      for( ii=0 ; ii < nt ; ii++ ) bf[ii] = fac ;
00378      EDIT_dset_items( dset , ADN_brick_fac,bf , ADN_none ) ;
00379      free(bf) ;
00380    }
00381 
00382    /*-- set byte order (for reading from disk) --*/
00383 
00384    ii = mri_short_order() ;
00385    if( doswap ) ii = REVERSE_ORDER(ii) ;
00386    dset->dblk->diskptr->byte_order = ii ;
00387 
00388    /*-- flag to read data from disk using ANALYZE mode --*/
00389 
00390    dset->dblk->diskptr->storage_mode = STORAGE_BY_ANALYZE ;
00391    strcpy( dset->dblk->diskptr->brick_name , iname ) ;
00392 
00393    RETURN(dset) ;
00394 }

THD_3dim_dataset* THD_open_ctfmri char *    fname
 

Open a CTF .mri file as an unpopulated AFNI dataset. It will be populated later, in THD_load_ctfmri(). -------------------------------------------------------------------

Definition at line 156 of file thd_ctfread.c.

References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, ANAT_MRAN_TYPE, BADBAD, THD_diskptr::brick_name, THD_diskptr::byte_order, Version_2_Header::clippingRange, DATABLOCK_MEM_MALLOC, Version_2_Header::dataSize, THD_3dim_dataset::dblk, THD_datablock::diskptr, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, HEAD_ANAT_TYPE, Version_2_Header::headModel, Version_2_Header::headOrigin_axial, Version_2_Header::headOrigin_coronal, Version_2_Header::headOrigin_sagittal, THD_3dim_dataset::idcode, Version_2_Header::identifierString, THD_ivec3::ijk, Version_2_Header::imageOrientation, Version_2_Header::imageSize, Version_2_Header::interpolatedFlag, HeadModel_Info::LeftEar_Axi, HeadModel_Info::LeftEar_Cor, HeadModel_Info::LeftEar_Sag, LOAD_IVEC3, MCW_hash_idcode(), MCW_strncpy, Version_2_Header::mmPerPixel_axial, Version_2_Header::mmPerPixel_coronal, Version_2_Header::mmPerPixel_sagittal, mri_short_order(), myXtNew, HeadModel_Info::Nasion_Axi, HeadModel_Info::Nasion_Cor, HeadModel_Info::Nasion_Sag, THD_usertaglist::num, nz, OR3OK, ORCODE, ORI_A2P_TYPE, ORI_L2R_TYPE, ORI_S2I_TYPE, Version_2_Header::originalSliceThickness, Version_2_Header::orthogonalFlag, RETURN, REVERSE_ORDER, HeadModel_Info::RightEar_Axi, HeadModel_Info::RightEar_Cor, HeadModel_Info::RightEar_Sag, Version_2_Header::rotate_axial, Version_2_Header::rotate_coronal, Version_2_Header::rotate_sagittal, THD_usertag::set, STORAGE_BY_CTFMRI, THD_diskptr::storage_mode, MCW_idcode::str, swap, swap_2(), swap_4(), THD_usertaglist::tag, TAG_SETLABEL, TAGLIST_SETLABEL, THD_3dim_dataset::tagset, THD_3dind_to_3dmm(), THD_3dmm_to_dicomm(), THD_filesize(), THD_MAX_PREFIX, THD_trailname(), THD_usertag::ti, Version_2_Header::transformMatrix, UNLOAD_FVEC3, THD_usertag::val, VERSION_22_STR, VIEW_ORIGINAL_TYPE, THD_usertag::x, THD_fvec3::xyz, THD_usertag::y, and THD_usertag::z.

Referenced by THD_init_session(), and THD_open_one_dataset().

00157 {
00158    FILE *fp ;
00159    Version_2_Header hh ;
00160    int ii,nn , swap ;
00161    THD_3dim_dataset *dset=NULL ;
00162    char prefix[THD_MAX_PREFIX] , *ppp , tname[12] , ori[4] ;
00163    THD_ivec3 nxyz , orixyz ;
00164    THD_fvec3 dxyz , orgxyz ;
00165    int iview ;
00166    int ngood , length , datum_type , datum_len , oxx,oyy,ozz ;
00167    int   nx,ny,nz ;
00168    float dx,dy,dz , xorg,yorg,zorg ;
00169 
00170 ENTRY("THD_open_ctfmri") ;
00171 
00172    /* open input file */
00173 
00174    if( fname == NULL || *fname == '\0' ) BADBAD("bad input filename");
00175    fp = fopen( fname , "rb" ) ;
00176    if( fp == NULL )                      BADBAD("can't open input file");
00177 
00178    /* read 1028 byte header */
00179 
00180    nn = fread( &hh , sizeof(hh) , 1 , fp ) ;
00181    fclose(fp) ;
00182    if( nn <= 0 )                         BADBAD("can't read input file");
00183 
00184    /* check if header string matches what we want */
00185 
00186    hh.identifierString[31] = '\0' ;  /* make sure is terminated */
00187    if( strcmp(hh.identifierString,VERSION_22_STR) != 0 ) BADBAD("bad version string");
00188    if( hh.imageSize == 0 )                               BADBAD("bad imageSize") ;
00189 
00190    /* determine if must swap header */
00191 
00192    swap = (hh.imageSize != 256) ;
00193 
00194    if( swap ){                          /* swap bytes in various header fields */
00195      swap_2(&hh.imageSize              ) ;
00196      swap_2(&hh.dataSize               ) ;
00197      swap_2(&hh.clippingRange          ) ;
00198      swap_2(&hh.imageOrientation       ) ;
00199      swap_4(&hh.mmPerPixel_sagittal    ) ;
00200      swap_4(&hh.mmPerPixel_coronal     ) ;
00201      swap_4(&hh.mmPerPixel_axial       ) ;
00202      swap_4(&hh.headOrigin_sagittal    ) ;
00203      swap_4(&hh.headOrigin_coronal     ) ;
00204      swap_4(&hh.headOrigin_axial       ) ;
00205      swap_4(&hh.rotate_coronal         ) ;
00206      swap_4(&hh.rotate_sagittal        ) ;
00207      swap_4(&hh.rotate_axial           ) ;
00208      swap_2(&hh.orthogonalFlag         ) ;
00209      swap_2(&hh.interpolatedFlag       ) ;
00210      swap_4(&hh.originalSliceThickness ) ;
00211      swap_2(&hh.headModel.Nasion_Sag   ) ;
00212      swap_2(&hh.headModel.Nasion_Cor   ) ;
00213      swap_2(&hh.headModel.Nasion_Axi   ) ;
00214      swap_2(&hh.headModel.LeftEar_Sag  ) ;
00215      swap_2(&hh.headModel.LeftEar_Cor  ) ;
00216      swap_2(&hh.headModel.LeftEar_Axi  ) ;
00217      swap_2(&hh.headModel.RightEar_Sag ) ;
00218      swap_2(&hh.headModel.RightEar_Cor ) ;
00219      swap_2(&hh.headModel.RightEar_Axi ) ;
00220 
00221      swap_4(&hh.transformMatrix[0][0]  ) ;   /* this stuff not used yet */
00222      swap_4(&hh.transformMatrix[0][1]  ) ;
00223      swap_4(&hh.transformMatrix[0][2]  ) ;
00224      swap_4(&hh.transformMatrix[0][3]  ) ;
00225      swap_4(&hh.transformMatrix[1][0]  ) ;
00226      swap_4(&hh.transformMatrix[1][1]  ) ;
00227      swap_4(&hh.transformMatrix[1][2]  ) ;
00228      swap_4(&hh.transformMatrix[1][3]  ) ;
00229      swap_4(&hh.transformMatrix[2][0]  ) ;
00230      swap_4(&hh.transformMatrix[2][1]  ) ;
00231      swap_4(&hh.transformMatrix[2][2]  ) ;
00232      swap_4(&hh.transformMatrix[2][3]  ) ;
00233      swap_4(&hh.transformMatrix[3][0]  ) ;
00234      swap_4(&hh.transformMatrix[3][1]  ) ;
00235      swap_4(&hh.transformMatrix[3][2]  ) ;
00236      swap_4(&hh.transformMatrix[3][3]  ) ;
00237    }
00238 
00239    /* simple checks on header stuff */
00240 
00241    if( hh.imageSize != 256           ||
00242        hh.dataSize  <  1             ||
00243        hh.dataSize  >  2             ||
00244        hh.mmPerPixel_sagittal <= 0.0 ||
00245        hh.mmPerPixel_coronal  <= 0.0 ||
00246        hh.mmPerPixel_axial    <= 0.0   ) BADBAD("bad header data") ;
00247 
00248    /*- 16 Mar 2005: instead of complaining about negative Origins,
00249                     just reset them to something semi-reasonable;
00250        I just get by with a little help from my friends
00251        - Zuxiang Li in this case.                                -*/
00252 
00253    if( hh.headOrigin_sagittal <= 0.0 ) hh.headOrigin_sagittal = hh.imageSize/2.;
00254    if( hh.headOrigin_coronal  <= 0.0 ) hh.headOrigin_coronal  = hh.imageSize/2.;
00255    if( hh.headOrigin_axial    <= 0.0 ) hh.headOrigin_axial    = hh.imageSize/2.;
00256 
00257    /* debugging code to print header information */
00258 #if 0
00259    printf("\n") ;
00260    printf("*** CTF MRI filename   = %s\n",fname                 ) ;
00261    printf("identifierString       = %s\n",hh.identifierString   ) ;
00262    printf("imageSize              = %d\n",hh.imageSize          ) ;
00263    printf("dataSize               = %d\n",hh.dataSize           ) ;
00264    printf("clippingRange          = %d\n",hh.clippingRange      ) ;
00265    printf("imageOrientation       = %d\n",hh.imageOrientation   ) ;
00266    printf("mmPerPixel_sagittal    = %f\n",hh.mmPerPixel_sagittal) ;
00267    printf("mmPerPixel_coronal     = %f\n",hh.mmPerPixel_coronal ) ;
00268    printf("mmPerPixel_axial       = %f\n",hh.mmPerPixel_axial   ) ;
00269    printf("headOrigin_sagittal    = %f\n",hh.headOrigin_sagittal) ;
00270    printf("headOrigin_coronal     = %f\n",hh.headOrigin_coronal ) ;
00271    printf("headOrigin_axial       = %f\n",hh.headOrigin_axial   ) ;
00272    printf("rotate_coronal         = %f\n",hh.rotate_coronal     ) ;
00273    printf("rotate_sagittal        = %f\n",hh.rotate_sagittal    ) ;
00274    printf("rotate_axial           = %f\n",hh.rotate_axial       ) ;
00275    printf("orthogonalFlag         = %d\n",hh.orthogonalFlag     ) ;
00276    printf("interpolatedFlag       = %d\n",hh.interpolatedFlag   ) ;
00277    printf("originalSliceThickness = %f\n",hh.originalSliceThickness ) ;
00278    printf("\n") ;
00279    printf("headModel.Nasion_Sag   = %d\n",hh.headModel.Nasion_Sag  ) ;
00280    printf("headModel.Nasion_Cor   = %d\n",hh.headModel.Nasion_Cor  ) ;
00281    printf("headModel.Nasion_Axi   = %d\n",hh.headModel.Nasion_Axi  ) ;
00282    printf("headModel.LeftEar_Sag  = %d\n",hh.headModel.LeftEar_Sag ) ;
00283    printf("headModel.LeftEar_Cor  = %d\n",hh.headModel.LeftEar_Cor ) ;
00284    printf("headModel.LeftEar_Axi  = %d\n",hh.headModel.LeftEar_Axi ) ;
00285    printf("headModel.RightEar_Sag = %d\n",hh.headModel.RightEar_Sag) ;
00286    printf("headModel.RightEar_Cor = %d\n",hh.headModel.RightEar_Cor) ;
00287    printf("headModel.RightEar_Axi = %d\n",hh.headModel.RightEar_Axi) ;
00288    printf("\n") ;
00289    printf("transformMatrix:\n"
00290           "  [ %9.4f %9.4f %9.4f %9.4f ]\n"
00291           "  [ %9.4f %9.4f %9.4f %9.4f ]\n"
00292           "  [ %9.4f %9.4f %9.4f %9.4f ]\n"
00293           "  [ %9.4f %9.4f %9.4f %9.4f ]\n" ,
00294       hh.transformMatrix[0][0] , hh.transformMatrix[0][1] ,
00295         hh.transformMatrix[0][2] , hh.transformMatrix[0][3] ,
00296       hh.transformMatrix[1][0] , hh.transformMatrix[1][1] ,
00297         hh.transformMatrix[1][2] , hh.transformMatrix[1][3] ,
00298       hh.transformMatrix[2][0] , hh.transformMatrix[2][1] ,
00299         hh.transformMatrix[2][2] , hh.transformMatrix[2][3] ,
00300       hh.transformMatrix[3][0] , hh.transformMatrix[3][1] ,
00301         hh.transformMatrix[3][2] , hh.transformMatrix[3][3]  ) ;
00302 #endif
00303 
00304    /* determine if file is big enough to hold all data it claims */
00305 
00306    nn = THD_filesize(fname) ;
00307    if( nn < hh.dataSize*hh.imageSize*hh.imageSize*hh.imageSize )
00308      BADBAD("input file too small") ;
00309 
00310    /*** from here, a lot of code is adapted from thd_analyzeread.c ***/
00311 
00312    datum_len = hh.dataSize ;
00313    switch( datum_len ){                         /* the only 2 cases */
00314      case 1:  datum_type = MRI_byte ; break ;
00315      case 2:  datum_type = MRI_short; break ;
00316    }
00317    nx = ny = nz = hh.imageSize ;              /* volumes are cubes! */
00318 
00319    /* set orientation:
00320       for now, assume (based on 1 sample) that data is stored in ASL or ASR order */
00321 
00322    ori[0] = 'A' ;          /* x is A-P */
00323    ori[1] = 'S' ;          /* y is S-I */
00324 
00325    /* determine if z is L-R or R-L from position of markers */
00326 
00327    ori[2] = (hh.headModel.LeftEar_Sag <= hh.headModel.RightEar_Sag) ? 'L' : 'R' ;
00328 
00329    oxx = ORCODE(ori[0]); oyy = ORCODE(ori[1]); ozz = ORCODE(ori[2]);
00330    if( !OR3OK(oxx,oyy,ozz) ){
00331      oxx = ORI_A2P_TYPE; oyy = ORI_S2I_TYPE; ozz = ORI_L2R_TYPE;   /** ASL? **/
00332    }
00333 
00334    /* now set grid size, keeping in mind that
00335        A-P is positive and P-A is negative,
00336        R-L is positive and L-R is negative,
00337        I-S is positive and S-I is negative.   */
00338 
00339    switch( ori[0] ){
00340      case 'A':  dx =  hh.mmPerPixel_coronal ; xorg = hh.headOrigin_coronal ; break ;
00341      case 'P':  dx = -hh.mmPerPixel_coronal ; xorg = hh.headOrigin_coronal ; break ;
00342      case 'R':  dx =  hh.mmPerPixel_sagittal; xorg = hh.headOrigin_sagittal; break ;
00343      case 'L':  dx = -hh.mmPerPixel_sagittal; xorg = hh.headOrigin_sagittal; break ;
00344      case 'I':  dx =  hh.mmPerPixel_axial   ; xorg = hh.headOrigin_axial   ; break ;
00345      case 'S':  dx = -hh.mmPerPixel_axial   ; xorg = hh.headOrigin_axial   ; break ;
00346    }
00347    switch( ori[1] ){
00348      case 'A':  dy =  hh.mmPerPixel_coronal ; yorg = hh.headOrigin_coronal ; break ;
00349      case 'P':  dy = -hh.mmPerPixel_coronal ; yorg = hh.headOrigin_coronal ; break ;
00350      case 'R':  dy =  hh.mmPerPixel_sagittal; yorg = hh.headOrigin_sagittal; break ;
00351      case 'L':  dy = -hh.mmPerPixel_sagittal; yorg = hh.headOrigin_sagittal; break ;
00352      case 'I':  dy =  hh.mmPerPixel_axial   ; yorg = hh.headOrigin_axial   ; break ;
00353      case 'S':  dy = -hh.mmPerPixel_axial   ; yorg = hh.headOrigin_axial   ; break ;
00354    }
00355    switch( ori[2] ){
00356      case 'A':  dz =  hh.mmPerPixel_coronal ; zorg = hh.headOrigin_coronal ; break ;
00357      case 'P':  dz = -hh.mmPerPixel_coronal ; zorg = hh.headOrigin_coronal ; break ;
00358      case 'R':  dz =  hh.mmPerPixel_sagittal; zorg = hh.headOrigin_sagittal; break ;
00359      case 'L':  dz = -hh.mmPerPixel_sagittal; zorg = hh.headOrigin_sagittal; break ;
00360      case 'I':  dz =  hh.mmPerPixel_axial   ; zorg = hh.headOrigin_axial   ; break ;
00361      case 'S':  dz = -hh.mmPerPixel_axial   ; zorg = hh.headOrigin_axial   ; break ;
00362    }
00363 
00364    /* At this point, (xorg,yorg,zorg) are voxel indices;
00365       now, translate them into shifts such that if voxel
00366       index ii is the location of x=0, then xorg+ii*dx=0. */
00367 
00368    xorg = -dx*xorg ; yorg = -dy*yorg ; zorg = -dz*zorg ;
00369 
00370    /*-- make a dataset --*/
00371 
00372    dset = EDIT_empty_copy(NULL) ;
00373 
00374    dset->idcode.str[0] = 'C' ;  /* overwrite 1st 3 bytes */
00375    dset->idcode.str[1] = 'T' ;
00376    dset->idcode.str[2] = 'F' ;
00377 
00378    MCW_hash_idcode( fname , dset ) ;  /* 06 May 2005 */
00379 
00380    ppp = THD_trailname(fname,0) ;                   /* strip directory */
00381    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;   /* to make prefix */
00382 
00383    nxyz.ijk[0] = nx ; dxyz.xyz[0] = dx ;  /* setup axes lengths and voxel sizes */
00384    nxyz.ijk[1] = ny ; dxyz.xyz[1] = dy ;
00385    nxyz.ijk[2] = nz ; dxyz.xyz[2] = dz ;
00386 
00387    orixyz.ijk[0] = oxx ; orgxyz.xyz[0] = xorg ;
00388    orixyz.ijk[1] = oyy ; orgxyz.xyz[1] = yorg ;
00389    orixyz.ijk[2] = ozz ; orgxyz.xyz[2] = zorg ;
00390 
00391    iview = VIEW_ORIGINAL_TYPE ;
00392 
00393    /*-- actually send the values above into the dataset header --*/
00394 
00395    EDIT_dset_items( dset ,
00396                       ADN_prefix      , prefix ,
00397                       ADN_datum_all   , datum_type ,
00398                       ADN_nxyz        , nxyz ,
00399                       ADN_xyzdel      , dxyz ,
00400                       ADN_xyzorg      , orgxyz ,
00401                       ADN_xyzorient   , orixyz ,
00402                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00403                       ADN_nvals       , 1 ,
00404                       ADN_type        , HEAD_ANAT_TYPE ,
00405                       ADN_view_type   , iview ,
00406                       ADN_func_type   , ANAT_MRAN_TYPE ,
00407                     ADN_none ) ;
00408 
00409    /*-- set byte order (for reading from disk) --*/
00410 
00411    ii = mri_short_order() ;
00412    if( swap ) ii = REVERSE_ORDER(ii) ;
00413    dset->dblk->diskptr->byte_order = ii ;
00414 
00415    /*-- flag to read data from disk using CTF MRI mode --*/
00416 
00417    dset->dblk->diskptr->storage_mode = STORAGE_BY_CTFMRI ;
00418    strcpy( dset->dblk->diskptr->brick_name , fname ) ;
00419 
00420    /*-- for fun, add a set of tags for MEG fiducial points, if present --*/
00421 
00422    if( hh.headModel.LeftEar_Sag != hh.headModel.RightEar_Sag ){
00423      THD_usertaglist *tagset = myXtNew(THD_usertaglist) ;
00424      int nas_ii,nas_jj,nas_kk , lft_ii,lft_jj,lft_kk , rgt_ii,rgt_jj,rgt_kk ;
00425      THD_fvec3 fv ; THD_ivec3 iv ;
00426 
00427      tagset->num = 3 ;
00428      TAGLIST_SETLABEL( tagset , "CTF MEG Fiducials" ) ;
00429 
00430      /* load voxel indexes into dataset of the 3 tag points;
00431         note we have to permute these into the dataset axes order */
00432 
00433      switch( ori[0] ){
00434        case 'P':
00435        case 'A':  nas_ii = hh.headModel.Nasion_Cor ;
00436                   lft_ii = hh.headModel.LeftEar_Cor ;
00437                   rgt_ii = hh.headModel.RightEar_Cor ; break ;
00438        case 'R':
00439        case 'L':  nas_ii = hh.headModel.Nasion_Sag ;
00440                   lft_ii = hh.headModel.LeftEar_Sag ;
00441                   rgt_ii = hh.headModel.RightEar_Sag ; break ;
00442        case 'I':
00443        case 'S':  nas_ii = hh.headModel.Nasion_Axi ;
00444                   lft_ii = hh.headModel.LeftEar_Axi ;
00445                   rgt_ii = hh.headModel.RightEar_Axi ; break ;
00446      }
00447      switch( ori[1] ){
00448        case 'P':
00449        case 'A':  nas_jj = hh.headModel.Nasion_Cor ;
00450                   lft_jj = hh.headModel.LeftEar_Cor ;
00451                   rgt_jj = hh.headModel.RightEar_Cor ; break ;
00452        case 'R':
00453        case 'L':  nas_jj = hh.headModel.Nasion_Sag ;
00454                   lft_jj = hh.headModel.LeftEar_Sag ;
00455                   rgt_jj = hh.headModel.RightEar_Sag ; break ;
00456        case 'I':
00457        case 'S':  nas_jj = hh.headModel.Nasion_Axi ;
00458                   lft_jj = hh.headModel.LeftEar_Axi ;
00459                   rgt_jj = hh.headModel.RightEar_Axi ; break ;
00460      }
00461      switch( ori[2] ){
00462        case 'P':
00463        case 'A':  nas_kk = hh.headModel.Nasion_Cor ;
00464                   lft_kk = hh.headModel.LeftEar_Cor ;
00465                   rgt_kk = hh.headModel.RightEar_Cor ; break ;
00466        case 'R':
00467        case 'L':  nas_kk = hh.headModel.Nasion_Sag ;
00468                   lft_kk = hh.headModel.LeftEar_Sag ;
00469                   rgt_kk = hh.headModel.RightEar_Sag ; break ;
00470        case 'I':
00471        case 'S':  nas_kk = hh.headModel.Nasion_Axi ;
00472                   lft_kk = hh.headModel.LeftEar_Axi ;
00473                   rgt_kk = hh.headModel.RightEar_Axi ; break ;
00474      }
00475 
00476      TAG_SETLABEL( tagset->tag[0] , "Nasion" ) ;
00477      LOAD_IVEC3( iv , nas_ii,nas_jj,nas_kk ) ;  /* compute DICOM  */
00478      fv = THD_3dind_to_3dmm( dset , iv ) ;      /* coordinates of */
00479      fv = THD_3dmm_to_dicomm( dset , fv ) ;     /* this point     */
00480      UNLOAD_FVEC3( fv , tagset->tag[0].x , tagset->tag[0].y , tagset->tag[0].z ) ;
00481      tagset->tag[0].val = 0.0 ;
00482      tagset->tag[0].ti  = 0 ;
00483      tagset->tag[0].set = 1 ;
00484 
00485      TAG_SETLABEL( tagset->tag[1] , "Left Ear" ) ;
00486      LOAD_IVEC3( iv , lft_ii,lft_jj,lft_kk ) ;
00487      fv = THD_3dind_to_3dmm( dset , iv ) ;
00488      fv = THD_3dmm_to_dicomm( dset , fv ) ;
00489      UNLOAD_FVEC3( fv , tagset->tag[1].x , tagset->tag[1].y , tagset->tag[1].z ) ;
00490      tagset->tag[1].val = 0.0 ;
00491      tagset->tag[1].ti  = 0 ;
00492      tagset->tag[1].set = 1 ;
00493 
00494      TAG_SETLABEL( tagset->tag[2] , "Right Ear" ) ;
00495      LOAD_IVEC3( iv , rgt_ii,rgt_jj,rgt_kk ) ;
00496      fv = THD_3dind_to_3dmm( dset , iv ) ;
00497      fv = THD_3dmm_to_dicomm( dset , fv ) ;
00498      UNLOAD_FVEC3( fv , tagset->tag[2].x , tagset->tag[2].y , tagset->tag[2].z ) ;
00499      tagset->tag[2].val = 0.0 ;
00500      tagset->tag[2].ti  = 0 ;
00501      tagset->tag[2].set = 1 ;
00502 
00503      dset->tagset = tagset ;
00504    }
00505 
00506    RETURN(dset) ;
00507 }

THD_3dim_dataset* THD_open_ctfsam char *    fname
 

Open a CTF .svl (SAM) file as an unpopulated AFNI dataset. It will be populated later, in THD_load_ctfsam(). -------------------------------------------------------------------

Definition at line 723 of file thd_ctfread.c.

References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, BADBAD, THD_diskptr::brick_name, SAM_HDR::BWFreq, THD_diskptr::byte_order, CTF_count(), DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, THD_datablock::diskptr, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, FUNC_FIM_TYPE, HEAD_FUNC_TYPE, SAM_HDR::HPFreq, THD_3dim_dataset::idcode, THD_ivec3::ijk, SAM_HDR::LeftPA, SAM_HDR::LPFreq, MCW_hash_idcode(), MCW_strncpy, SAM_HDR::MeanNoise, mri_short_order(), SAM_HDR::MriName, SAM_HDR::Nasion, SAM_HDR::NumChans, SAM_HDR::NumWeights, nz, OR3OK, ORCODE, ORI_I2S_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, RETURN, REVERSE_ORDER, SAM_HDR::RightPA, SAM_HDR::SAMType, SAM_HDR::SAMUnit, SAM_HDR::SetName, SAM_HDR::StepSize, STORAGE_BY_CTFSAM, THD_diskptr::storage_mode, MCW_idcode::str, swap, swap_4(), swap_8(), THD_filesize(), THD_MAX_PREFIX, THD_trailname(), SAM_HDR::Version, VIEW_ORIGINAL_TYPE, SAM_HDR::XEnd, SAM_HDR::XStart, THD_fvec3::xyz, SAM_HDR::YEnd, SAM_HDR::YStart, SAM_HDR::ZEnd, and SAM_HDR::ZStart.

Referenced by THD_init_session(), and THD_open_one_dataset().

00724 {
00725    FILE *fp ;
00726    SAM_HDR hh ;
00727    char Identity[9] ;
00728    int ii,nn , swap ;
00729    THD_3dim_dataset *dset=NULL ;
00730    char prefix[THD_MAX_PREFIX] , *ppp , tname[12] , ori[4] ;
00731    THD_ivec3 nxyz , orixyz ;
00732    THD_fvec3 dxyz , orgxyz ;
00733    int iview ;
00734    int ngood , length , datum_type , datum_len , oxx,oyy,ozz ;
00735    int   nx,ny,nz ;
00736    float dx,dy,dz , xorg,yorg,zorg ;
00737 
00738 ENTRY("THD_open_ctfsam") ;
00739 
00740    /* open input file */
00741 
00742    if( fname == NULL || *fname == '\0' ) BADBAD("bad input filename");
00743    fp = fopen( fname , "rb" ) ;
00744    if( fp == NULL )                      BADBAD("can't open input file");
00745 
00746    /* read header [1st 8 bytes are "SAMIMAGE"] */
00747 
00748    fread( Identity , 1,8 , fp ) ; Identity[8] = '\0' ;
00749    fread( &hh , sizeof(hh) , 1 , fp ) ;
00750    fclose(fp) ;
00751 
00752    if( strcmp(Identity,"SAMIMAGE") != 0 ) BADBAD("Identity != SAMIMAGE") ;
00753    if( hh.Version                  == 0 ) BADBAD("bad header Version") ;
00754 
00755    swap = (hh.Version < 0) || (hh.Version > 3) ;    /* byte swap? */
00756 
00757    if( swap ){                   /* swap various header fields */
00758      swap_4( &hh.Version    ) ;
00759      swap_4( &hh.NumChans   ) ;
00760      swap_4( &hh.NumWeights ) ;
00761      swap_8( &hh.XStart     ) ;
00762      swap_8( &hh.XEnd       ) ;
00763      swap_8( &hh.YStart     ) ;
00764      swap_8( &hh.YEnd       ) ;
00765      swap_8( &hh.ZStart     ) ;
00766      swap_8( &hh.ZEnd       ) ;
00767      swap_8( &hh.StepSize   ) ;
00768      swap_8( &hh.HPFreq     ) ;
00769      swap_8( &hh.LPFreq     ) ;
00770      swap_8( &hh.BWFreq     ) ;
00771      swap_8( &hh.MeanNoise  ) ;
00772      swap_4( &hh.Nasion[0]  ) ;
00773      swap_4( &hh.RightPA[0] ) ;
00774      swap_4( &hh.LeftPA[0]  ) ;
00775      swap_4( &hh.Nasion[1]  ) ;
00776      swap_4( &hh.RightPA[1] ) ;
00777      swap_4( &hh.LeftPA[1]  ) ;
00778      swap_4( &hh.Nasion[2]  ) ;
00779      swap_4( &hh.RightPA[2] ) ;
00780      swap_4( &hh.LeftPA[2]  ) ;
00781      swap_4( &hh.SAMType    ) ;
00782      swap_4( &hh.SAMUnit    ) ;
00783    }
00784 
00785    /* simple checks on header values */
00786 
00787    if( hh.Version  < 0        ||
00788        hh.Version  > 3        ||  /* 26 Feb 2005 */
00789        hh.XStart   >= hh.XEnd ||
00790        hh.YStart   >= hh.YEnd ||
00791        hh.ZStart   >= hh.ZEnd ||
00792        hh.StepSize <= 0.0       ) BADBAD("bad header data") ;
00793 
00794 #if 0
00795    printf("\n") ;
00796    printf("**CTF SAM : %s\n",fname) ;
00797    printf("Version   = %d\n",hh.Version) ;
00798    printf("NumChans  = %d\n",hh.NumChans) ;
00799    printf("NumWeights= %d\n",hh.NumWeights) ;
00800    printf("XStart    = %g\n",hh.XStart) ;
00801    printf("Xend      = %g\n",hh.XEnd) ;
00802    printf("YStart    = %g\n",hh.YStart) ;
00803    printf("YEnd      = %g\n",hh.YEnd) ;
00804    printf("ZStart    = %g\n",hh.ZStart) ;
00805    printf("Zend      = %g\n",hh.ZEnd) ;
00806    printf("StepSize  = %g\n",hh.StepSize) ;
00807    printf("HPFreq    = %g\n",hh.HPFreq) ;
00808    printf("LPFreq    = %g\n",hh.LPFreq) ;
00809    printf("BWFreq    = %g\n",hh.BWFreq) ;
00810    printf("MeanNoise = %g\n",hh.MeanNoise) ;
00811    printf("Nasion[0] = %d\n",hh.Nasion[0]) ;
00812    printf("Nasion[1] = %d\n",hh.Nasion[1]) ;
00813    printf("Nasion[2] = %d\n",hh.Nasion[2]) ;
00814    printf("RightPA[0]= %d\n",hh.RightPA[0]) ;
00815    printf("RightPA[1]= %d\n",hh.RightPA[1]) ;
00816    printf("RightPA[2]= %d\n",hh.RightPA[2]) ;
00817    printf("LeftPA[0] = %d\n",hh.LeftPA[0]) ;
00818    printf("LeftPA[1] = %d\n",hh.LeftPA[1]) ;
00819    printf("LeftPA[2] = %d\n",hh.LeftPA[2]) ;
00820    printf("SAMtype   = %d\n",hh.SAMType) ;
00821    printf("SAMunit   = %d\n",hh.SAMUnit) ;
00822    printf("SetName   = %s\n",hh.SetName) ;
00823    printf("MriName   = %s\n",hh.MriName) ;
00824    printf("headersize= %d\n",sizeof(hh)+8) ;
00825 #endif
00826 
00827    hh.StepSize *= 1000.0 ;   /* convert distances from m to mm */
00828    hh.XStart   *= 1000.0 ;   /* (who the hell uses meters for brain imaging?) */
00829    hh.YStart   *= 1000.0 ;   /* (blue whales?  elephants?) */
00830    hh.ZStart   *= 1000.0 ;
00831    hh.XEnd     *= 1000.0 ;
00832    hh.YEnd     *= 1000.0 ;
00833    hh.ZEnd     *= 1000.0 ;
00834 
00835    dx = dy = dz = hh.StepSize ;  /* will be altered below */
00836 
00837 #if 0
00838    nx = (int)((hh.ZEnd - hh.ZStart)/dz + 0.99999); /* dataset is stored in Z,Y,X order */
00839    ny = (int)((hh.YEnd - hh.YStart)/dy + 0.99999); /* but AFNI calls these x,y,z       */
00840    nz = (int)((hh.XEnd - hh.XStart)/dx + 0.99999);
00841 #else
00842    nx = CTF_count( hh.ZStart , hh.ZEnd , hh.StepSize ) ;
00843    ny = CTF_count( hh.YStart , hh.YEnd , hh.StepSize ) ;
00844    nz = CTF_count( hh.XStart , hh.XEnd , hh.StepSize ) ;
00845 #endif
00846 
00847    /* determine if file is big enough to hold all data it claims */
00848 
00849    nn = THD_filesize(fname) ;
00850    if( nn < sizeof(double)*nx*ny*nz ) BADBAD("input file too small") ;
00851 
00852    datum_type = MRI_float ;  /* actually is double, but AFNI doesn't grok that */
00853                              /* will be converted to floats when reading data */
00854 
00855    /* set orientation = IRP = xyz ordering */
00856 
00857    ori[0] = 'I'; ori[1] = 'R'; ori[2] = 'P';
00858 
00859    oxx = ORCODE(ori[0]); oyy = ORCODE(ori[1]); ozz = ORCODE(ori[2]);
00860    if( !OR3OK(oxx,oyy,ozz) ){
00861      oxx = ORI_I2S_TYPE; oyy = ORI_R2L_TYPE; ozz = ORI_P2A_TYPE;   /** IRP? **/
00862    }
00863 
00864    orixyz.ijk[0] = oxx ; orixyz.ijk[1] = oyy ; orixyz.ijk[2] = ozz ;
00865 
00866    /* now set grid size, keeping in mind that
00867       A-P is positive and P-A is negative,
00868       R-L is positive and L-R is negative,
00869       I-S is positive and S-I is negative.       */
00870 
00871    switch( ori[0] ){
00872      case 'A':  dx =  hh.StepSize ; xorg = -hh.XStart ; break ;
00873      case 'P':  dx = -hh.StepSize ; xorg = -hh.XStart ; break ;
00874      case 'R':  dx =  hh.StepSize ; xorg =  hh.YStart ; break ;
00875      case 'L':  dx = -hh.StepSize ; xorg =  hh.YStart ; break ;
00876      case 'I':  dx =  hh.StepSize ; xorg =  hh.ZStart ; break ;
00877      case 'S':  dx = -hh.StepSize ; xorg =  hh.ZStart ; break ;
00878    }
00879    switch( ori[1] ){
00880      case 'A':  dy =  hh.StepSize ; yorg = -hh.XStart ; break ;
00881      case 'P':  dy = -hh.StepSize ; yorg = -hh.XStart ; break ;
00882      case 'R':  dy =  hh.StepSize ; yorg =  hh.YStart ; break ;
00883      case 'L':  dy = -hh.StepSize ; yorg =  hh.YStart ; break ;
00884      case 'I':  dy =  hh.StepSize ; yorg =  hh.ZStart ; break ;
00885      case 'S':  dy = -hh.StepSize ; yorg =  hh.ZStart ; break ;
00886    }
00887    switch( ori[2] ){
00888      case 'A':  dz =  hh.StepSize ; zorg = -hh.XStart ; break ;
00889      case 'P':  dz = -hh.StepSize ; zorg = -hh.XStart ; break ;
00890      case 'R':  dz =  hh.StepSize ; zorg =  hh.YStart ; break ;
00891      case 'L':  dz = -hh.StepSize ; zorg =  hh.YStart ; break ;
00892      case 'I':  dz =  hh.StepSize ; zorg =  hh.ZStart ; break ;
00893      case 'S':  dz = -hh.StepSize ; zorg =  hh.ZStart ; break ;
00894    }
00895 
00896    /*-- make a dataset --*/
00897 
00898    dset = EDIT_empty_copy(NULL) ;
00899 
00900    dset->idcode.str[0] = 'C' ;  /* overwrite 1st 3 bytes */
00901    dset->idcode.str[1] = 'T' ;
00902    dset->idcode.str[2] = 'F' ;
00903 
00904    MCW_hash_idcode( fname , dset ) ;  /* 06 May 2005 */
00905 
00906    ppp = THD_trailname(fname,0) ;                   /* strip directory */
00907    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;   /* to make prefix */
00908 
00909    nxyz.ijk[0] = nx ; dxyz.xyz[0] = dx ;  /* setup axes lengths and voxel sizes */
00910    nxyz.ijk[1] = ny ; dxyz.xyz[1] = dy ;
00911    nxyz.ijk[2] = nz ; dxyz.xyz[2] = dz ;
00912 
00913    orixyz.ijk[0] = oxx ; orgxyz.xyz[0] = xorg ;
00914    orixyz.ijk[1] = oyy ; orgxyz.xyz[1] = yorg ;
00915    orixyz.ijk[2] = ozz ; orgxyz.xyz[2] = zorg ;
00916 
00917    iview = VIEW_ORIGINAL_TYPE ;
00918 
00919    /*-- actually send the values above into the dataset header --*/
00920 
00921    EDIT_dset_items( dset ,
00922                       ADN_prefix      , prefix ,
00923                       ADN_datum_all   , datum_type ,
00924                       ADN_nxyz        , nxyz ,
00925                       ADN_xyzdel      , dxyz ,
00926                       ADN_xyzorg      , orgxyz ,
00927                       ADN_xyzorient   , orixyz ,
00928                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00929                       ADN_nvals       , 1 ,
00930                       ADN_type        , HEAD_FUNC_TYPE ,
00931                       ADN_view_type   , iview ,
00932                       ADN_func_type   , FUNC_FIM_TYPE ,
00933                     ADN_none ) ;
00934 
00935    /*-- set byte order (for reading from disk) --*/
00936 
00937    ii = mri_short_order() ;
00938    if( swap ) ii = REVERSE_ORDER(ii) ;
00939    dset->dblk->diskptr->byte_order = ii ;
00940 
00941    /*-- flag to read data from disk using CTF SAM mode --*/
00942 
00943    dset->dblk->diskptr->storage_mode = STORAGE_BY_CTFSAM ;
00944    strcpy( dset->dblk->diskptr->brick_name , fname ) ;
00945 
00946    RETURN(dset) ;
00947 }

THD_3dim_dataset* THD_open_dataset char *   
 

Definition at line 21 of file thd_mastery.c.

References THD_3dim_dataset::dblk, DSET_NVALS, ENTRY, free, malloc, THD_datablock::master_bot, THD_datablock::master_top, MCW_get_intlist(), MIN, RETURN, STRING_HAS_SUFFIX, THD_fetch_dataset(), THD_MAX_NAME, THD_open_1D(), THD_open_3dcalc(), THD_open_one_dataset(), THD_open_tcat(), THD_setup_mastery(), and top.

Referenced by AFNI_read_inputs(), basis_write_iresp(), basis_write_sresp(), CALC_read_opts(), check_one_output_file(), create_bucket(), cubic_spline(), do_xrestore_stuff(), DT_read_opts(), form_clusters(), get_dimensions(), get_inputs(), get_options(), HI_read_opts(), init_floatvector_array(), init_options(), initialize_program(), main(), MRG_read_opts(), openDataset(), PC_read_opts(), read_input_data(), SUMA_FormAfnidset(), SUMA_Get_isosurface_datasets(), SUMA_VolPar_Attr(), terminate(), THD_load_tcat(), THD_open_one_dataset(), THD_open_tcat(), UC_read_opts(), validate_datasets(), VL_command_line(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket_data(), write_ts_array(), and ZCAT_read_opts().

00022 {
00023    THD_3dim_dataset *dset ;
00024    char dname[THD_MAX_NAME] , subv[THD_MAX_NAME] ;
00025    char *cpt , *bpt ;
00026    int  *ivlist=NULL ;
00027    int    ii , jj , kk ;
00028    float  bot=1.0 , top=0.0 ;
00029 
00030 ENTRY("THD_open_dataset") ;
00031 
00032    /*-- sanity check --*/
00033 
00034    if( pathname == NULL            ||
00035        (ii=strlen(pathname)) == 0  ||
00036        pathname[ii-1]        == '/'  ) RETURN(NULL) ;
00037 
00038    /*-- 23 Mar 2001: perhaps get from across the Web --*/
00039 
00040    if( strncmp(pathname,"http://",7) == 0 ||
00041        strncmp(pathname,"ftp://" ,6) == 0   ){
00042 
00043       dset = THD_fetch_dataset( pathname ) ;
00044       RETURN(dset) ;
00045    }
00046 
00047    /*-- 17 Mar 2000: check if this is a 3dcalc() run --*/
00048 
00049    if( strncmp(pathname,"3dcalc(",7)  == 0 ){
00050      dset = THD_open_3dcalc( pathname ) ;
00051      RETURN(dset) ;
00052    }
00053 
00054    /*-- 04 Mar 2003: allow input of .1D files   --*/
00055    /*--              which deals with [] itself --*/
00056 
00057    if( strstr(pathname,".1D") != NULL ){
00058      dset = THD_open_1D( pathname ) ;
00059      if( dset != NULL ) RETURN(dset) ;
00060    }
00061 
00062    /*-- 04 Aug 2004: allow input of a list of dataset, separated by spaces --*/
00063 
00064    if( strchr(pathname,' ') != NULL ){
00065      dset = THD_open_tcat( pathname ) ;
00066      RETURN(dset) ;
00067    }
00068 
00069    /*-- find the opening "[" and/or "<" --*/
00070 
00071    cpt = strstr(pathname,"[") ;
00072    bpt = strstr(pathname,"<") ;  /* 21 Feb 2001 */
00073 
00074    if( cpt == NULL && bpt == NULL ){            /* no "[" or "<"  */
00075      dset = THD_open_one_dataset( pathname ) ;  /* ==> open      */
00076      RETURN(dset) ;                             /*     normally */
00077    }
00078 
00079    if( cpt == pathname || bpt == pathname ) RETURN(NULL);  /* error */
00080 
00081    /* copy dataset filename to dname and selector string to subv */
00082 
00083    ii = (cpt != NULL ) ? cpt - pathname : 999999 ;
00084    jj = (bpt != NULL ) ? bpt - pathname : 999999 ;
00085    kk = MIN(ii,jj) ;
00086    memcpy(dname,pathname,kk) ; dname[kk] = '\0' ;
00087 
00088    if( STRING_HAS_SUFFIX(dname,".mnc")    ||
00089        STRING_HAS_SUFFIX(dname,".hdr")    ||
00090        STRING_HAS_SUFFIX(dname,".nia")    ||
00091        STRING_HAS_SUFFIX(dname,".nii")    ||
00092        STRING_HAS_SUFFIX(dname,".nii.gz") ||
00093        STRING_HAS_SUFFIX(dname,".mri")    ||
00094        STRING_HAS_SUFFIX(dname,".svl")      ){
00095 
00096      fprintf(stderr,"** Can't use selectors on dataset: %s\n",pathname) ;
00097      RETURN(NULL) ;
00098    }
00099 
00100    /* open the dataset */
00101 
00102    dset = THD_open_one_dataset( dname ) ;
00103    if( dset == NULL ) RETURN(NULL) ;
00104 
00105    /* parse the sub-brick selector string (if any) */
00106 
00107    if( cpt != NULL ){
00108      char *qpt ;
00109      strcpy(subv,cpt) ;
00110      qpt = strstr(subv,"<") ; if( qpt != NULL ) *qpt = '\0' ;
00111      ivlist = MCW_get_intlist( DSET_NVALS(dset) , subv ) ;
00112    }
00113    if( ivlist == NULL ){
00114      if( cpt != NULL )
00115        fprintf(stderr,"** WARNING: bad sub-brick selector => using [0..%d]\n",
00116                DSET_NVALS(dset)-1) ;
00117      ivlist = (int *) malloc(sizeof(int)*(DSET_NVALS(dset)+1)) ;
00118      ivlist[0] = DSET_NVALS(dset) ;
00119      for( kk=0 ; kk < ivlist[0] ; kk++ ) ivlist[kk+1] = kk ;
00120    }
00121 
00122    /* 21 Feb 2001: if present, load the sub-range data */
00123 
00124    if( bpt != NULL ){
00125       char *dpt = strstr(bpt,"..") ;
00126 #if 0
00127 fprintf(stderr,"bpt=%s\n",bpt) ;
00128 #endif
00129       if( dpt != NULL ){
00130 #if 0
00131 fprintf(stderr,"dpt=%s\n",dpt) ;
00132 #endif
00133          kk  = sscanf( bpt+1 , "%f" , &bot ) ;
00134          kk += sscanf( dpt+2 , "%f" , &top ) ;
00135          if( kk == 2 && bot <= top ){
00136             dset->dblk->master_bot = bot ;
00137             dset->dblk->master_top = top ;
00138          } else {
00139             dset->dblk->master_bot = 1.0 ;
00140             dset->dblk->master_top = 0.0 ;
00141          }
00142       }
00143    }
00144 
00145    /* modify the dataset according to the selector string */
00146 
00147    THD_setup_mastery( dset , ivlist ) ;
00148    free(ivlist) ;
00149 
00150    RETURN(dset) ;
00151 }

THD_3dim_dataset* THD_open_minc char *   
 

Definition at line 113 of file thd_mincread.c.

References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, AFMALL, mincdim::afni_orient, AFNI_yesenv(), ANAT_BUCK_TYPE, ANAT_EPI_TYPE, ANAT_MRAN_TYPE, THD_diskptr::brick_name, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, mincdim::dimid, THD_datablock::diskptr, EDIT_BRICK_LABEL, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, EPR, first_err, fname_err, free, mincdim::good, HEAD_ANAT_TYPE, THD_3dim_dataset::idcode, THD_ivec3::ijk, mincdim::len, MCW_hash_idcode(), MCW_strncpy, nc_close(), nc_get_att_float(), nc_get_att_text(), nc_inq_attlen(), nc_inq_dimlen(), nc_inq_dimname(), nc_inq_vardimid(), nc_inq_varid(), nc_inq_varndims(), nc_inq_vartype(), nc_open(), ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, read_mincdim(), RETURN, mincdim::start, mincdim::step, STORAGE_BY_MINC, THD_diskptr::storage_mode, MCW_idcode::str, THD_MAX_PREFIX, THD_trailname(), tross_Append_History(), UNITS_SEC_TYPE, VIEW_ORIGINAL_TYPE, VIEW_TALAIRACH_TYPE, xspace, THD_fvec3::xyz, and yspace.

Referenced by main(), THD_init_session(), and THD_open_one_dataset().

00114 {
00115    THD_3dim_dataset *dset=NULL ;
00116    int ncid , code ;
00117    mincdim xspace , yspace , zspace , *xyz[3] ;
00118    int im_varid , im_rank , im_dimid[4] ;
00119    nc_type im_type ;
00120 
00121    char prefix[1024] , *ppp , tname[12] ;
00122    THD_ivec3 nxyz , orixyz ;
00123    THD_fvec3 dxyz , orgxyz ;
00124    int datum , nvals=1 , ibr , iview ;
00125    size_t len ;
00126    float dtime=1.0 ;
00127 
00128 ENTRY("THD_open_minc") ;
00129 
00130    /*-- open input file --*/
00131 
00132    if( pathname == NULL || pathname[0] == '\0' ) RETURN(NULL);
00133 
00134    first_err = 1 ;        /* put a newline before 1st error message */
00135    fname_err = pathname ; /* filename for errors in read_mincdim()  */
00136 
00137    code = nc_open( pathname , NC_NOWRITE , &ncid ) ;
00138    if( code != NC_NOERR ){ EPR(code,pathname,"open"); RETURN(NULL); }
00139 
00140    /*---------- get info about spatial axes ---------*/
00141    /*[[ MINC x and y are reversed relative to AFNI ]]*/
00142    /*[[ MINC x=L-R y=P-A;  AFNI x=R-L y=A-P; z=I-S ]]*/
00143 
00144    xspace = read_mincdim( ncid , "xspace" ) ;
00145    xspace.step = -xspace.step ; xspace.start = -xspace.start ;
00146    xspace.afni_orient = (xspace.step < 0.0) ? ORI_L2R_TYPE : ORI_R2L_TYPE ;
00147 
00148    yspace = read_mincdim( ncid , "yspace" ) ;
00149    yspace.step = -yspace.step ; yspace.start = -yspace.start ;
00150    yspace.afni_orient = (yspace.step < 0.0) ? ORI_P2A_TYPE : ORI_A2P_TYPE ;
00151 
00152    zspace = read_mincdim( ncid , "zspace" ) ;
00153    zspace.afni_orient = (zspace.step > 0.0) ? ORI_I2S_TYPE : ORI_S2I_TYPE ;
00154 
00155    /*-- if don't have all 3 named dimensions, quit --*/
00156 
00157    if( !xspace.good || !yspace.good || !zspace.good ){
00158       nc_close(ncid) ; RETURN(NULL) ;
00159    }
00160 
00161    /*-- get info about the image data --*/
00162 
00163    code = nc_inq_varid( ncid , "image" , &im_varid ) ;
00164    if( code != NC_NOERR ){ EPR(code,pathname,"image varid"); nc_close(ncid); RETURN(NULL); }
00165 
00166    if( !AFNI_yesenv("AFNI_MINC_FLOATIZE") ){  /* determine type of dataset values */
00167       code = nc_inq_vartype( ncid , im_varid , &im_type ) ;
00168       if( code != NC_NOERR ){ EPR(code,pathname,"image vartype"); nc_close(ncid); RETURN(NULL); }
00169       switch( im_type ){
00170          default:
00171             if( first_err ){ fprintf(stderr,"\n"); first_err=0; }
00172             fprintf(stderr,"** MINC error: can't handle image type code %d\n",im_type);
00173             nc_close(ncid); RETURN(NULL);
00174          break ;
00175 
00176          case NC_BYTE:  datum = MRI_byte  ; break ;
00177 
00178          case NC_SHORT: datum = MRI_short ; break ;
00179 
00180          case NC_FLOAT:
00181          case NC_DOUBLE:
00182          case NC_INT:   datum = MRI_float ; break ;
00183       }
00184    } else {                               /* always read in as floats if */
00185       datum = MRI_float ;                 /* AFNI_MINC_FLOATIZE is Yes   */
00186    }
00187 
00188    /* we allow nD mages only for n=3 or n=4 */
00189 
00190    code = nc_inq_varndims( ncid , im_varid , &im_rank ) ;
00191    if( code != NC_NOERR ){ EPR(code,pathname,"image varndims"); nc_close(ncid); RETURN(NULL); }
00192    if( im_rank < 3 || im_rank > 4 ){
00193       if( first_err ){ fprintf(stderr,"\n"); first_err=0; }
00194       fprintf(stderr,"** MINC error: image rank=%d\n",im_rank) ;
00195       nc_close(ncid); RETURN(NULL);
00196    }
00197 
00198    code = nc_inq_vardimid( ncid , im_varid , im_dimid ) ;
00199    if( code != NC_NOERR ){ EPR(code,pathname,"image vardimid"); nc_close(ncid); RETURN(NULL); }
00200 
00201    /*-- find axes order --*/
00202 
00203      /* fastest variation */
00204 
00205         if( im_dimid[im_rank-1] == xspace.dimid ) xyz[0] = &xspace ;
00206    else if( im_dimid[im_rank-1] == yspace.dimid ) xyz[0] = &yspace ;
00207    else if( im_dimid[im_rank-1] == zspace.dimid ) xyz[0] = &zspace ;
00208    else {
00209       if( first_err ){ fprintf(stderr,"\n"); first_err=0; }
00210       fprintf(stderr,"** MINC error: image dim[2] illegal\n") ;
00211       nc_close(ncid) ; RETURN(NULL) ;
00212    }
00213 
00214      /* next fastest variation */
00215 
00216         if( im_dimid[im_rank-2] == xspace.dimid ) xyz[1] = &xspace ;
00217    else if( im_dimid[im_rank-2] == yspace.dimid ) xyz[1] = &yspace ;
00218    else if( im_dimid[im_rank-2] == zspace.dimid ) xyz[1] = &zspace ;
00219    else {
00220       if( first_err ){ fprintf(stderr,"\n"); first_err=0; }
00221       fprintf(stderr,"** MINC error: image dim[1] illegal\n") ;
00222       nc_close(ncid) ; RETURN(NULL) ;
00223    }
00224 
00225      /* slowest variation */
00226 
00227         if( im_dimid[im_rank-3] == xspace.dimid ) xyz[2] = &xspace ;
00228    else if( im_dimid[im_rank-3] == yspace.dimid ) xyz[2] = &yspace ;
00229    else if( im_dimid[im_rank-3] == zspace.dimid ) xyz[2] = &zspace ;
00230    else {
00231       if( first_err ){ fprintf(stderr,"\n"); first_err=0; }
00232       fprintf(stderr,"** MINC error: image dim[0] illegal\n") ;
00233       nc_close(ncid) ; RETURN(NULL) ;
00234    }
00235 
00236    /*-- determine the length of the 4th dimension, if any --*/
00237 
00238    strcpy(tname,"MINC") ;  /* default name for 4th dimension */
00239 
00240    if( im_rank == 4 ){
00241       char fname[NC_MAX_NAME+4] ;
00242       code = nc_inq_dimlen( ncid , im_dimid[0] , &len ) ;
00243       if( code != NC_NOERR ){ EPR(code,pathname,"dimid[0] dimlen"); nc_close(ncid); RETURN(NULL); }
00244 
00245       nvals = len ;  /* number of volumes in this file */
00246 
00247       /* get the name of this dimension */
00248 
00249       code = nc_inq_dimname( ncid , im_dimid[0] , fname ) ;
00250       if( code == NC_NOERR ){
00251          MCW_strncpy(tname,fname,10) ;
00252       }
00253 
00254       /* get the stepsize of this dimension */
00255 
00256       code = nc_get_att_float( ncid , im_dimid[0] , "step" , &dtime ) ;
00257       if( code != NC_NOERR || dtime <= 0.0 ) dtime = 1.0 ;
00258    }
00259 
00260    /*-- make a dataset --*/
00261 
00262    dset = EDIT_empty_copy(NULL) ;
00263 
00264    ppp  = THD_trailname(pathname,0) ;               /* strip directory */
00265    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;   /* to make prefix */
00266 
00267    nxyz.ijk[0] = xyz[0]->len ; dxyz.xyz[0] = xyz[0]->step ;  /* setup axes */
00268    nxyz.ijk[1] = xyz[1]->len ; dxyz.xyz[1] = xyz[1]->step ;
00269    nxyz.ijk[2] = xyz[2]->len ; dxyz.xyz[2] = xyz[2]->step ;
00270 
00271    orixyz.ijk[0] = xyz[0]->afni_orient ; orgxyz.xyz[0] = xyz[0]->start ;
00272    orixyz.ijk[1] = xyz[1]->afni_orient ; orgxyz.xyz[1] = xyz[1]->start ;
00273    orixyz.ijk[2] = xyz[2]->afni_orient ; orgxyz.xyz[2] = xyz[2]->start ;
00274 
00275    if( strstr(xyz[0]->spacetype,"alairach") != NULL ){  /* coord system */
00276       iview = VIEW_TALAIRACH_TYPE ;
00277    } else {
00278       iview = VIEW_ORIGINAL_TYPE ;
00279    }
00280 
00281    dset->idcode.str[0] = 'M' ;  /* overwrite 1st 3 bytes with something special */
00282    dset->idcode.str[1] = 'N' ;
00283    dset->idcode.str[2] = 'C' ;
00284 
00285    MCW_hash_idcode( pathname , dset ) ;  /* 06 May 2005 */
00286 
00287    EDIT_dset_items( dset ,
00288                       ADN_prefix      , prefix ,
00289                       ADN_datum_all   , datum ,
00290                       ADN_nxyz        , nxyz ,
00291                       ADN_xyzdel      , dxyz ,
00292                       ADN_xyzorg      , orgxyz ,
00293                       ADN_xyzorient   , orixyz ,
00294                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00295                       ADN_nvals       , nvals ,
00296                       ADN_type        , HEAD_ANAT_TYPE ,
00297                       ADN_view_type   , iview ,
00298                       ADN_func_type   , (nvals==1) ? ANAT_MRAN_TYPE
00299                                                    : ANAT_BUCK_TYPE ,
00300                     ADN_none ) ;
00301 
00302    if( nvals > 9 )              /* pretend it is 3D+time */
00303       EDIT_dset_items( dset ,
00304                          ADN_func_type, ANAT_EPI_TYPE ,
00305                          ADN_ntt      , nvals ,
00306                          ADN_ttorg    , 0.0 ,
00307                          ADN_ttdel    , dtime ,
00308                          ADN_ttdur    , 0.0 ,
00309                          ADN_tunits   , UNITS_SEC_TYPE ,
00310                        ADN_none ) ;
00311 
00312    /*-- flag to read data from disk using MINC/netCDF functions --*/
00313 
00314    dset->dblk->diskptr->storage_mode = STORAGE_BY_MINC ;
00315    strcpy( dset->dblk->diskptr->brick_name , pathname ) ;
00316 
00317    for( ibr=0 ; ibr < nvals ; ibr++ ){     /* make sub-brick labels */
00318       sprintf(prefix,"%s[%d]",tname,ibr) ;
00319       EDIT_BRICK_LABEL( dset , ibr , prefix ) ;
00320    }
00321 
00322    /*-- read and save the global:history attribute --*/
00323 
00324 #if 0
00325    sprintf(prefix,"THD_open_minc(%s)",pathname) ;
00326    tross_Append_History( dset , prefix ) ;
00327 #endif
00328 
00329    code = nc_inq_attlen( ncid , NC_GLOBAL , "history" , &len ) ;
00330    if( code == NC_NOERR && len > 0 ){
00331       ppp = AFMALL(char,len+4) ;
00332       code = nc_get_att_text( ncid , NC_GLOBAL , "history" , ppp ) ;
00333       if( code == NC_NOERR ){  /* should always happen */
00334          ppp[len] = '\0' ;
00335          tross_Append_History( dset , ppp ) ;
00336       }
00337       free(ppp) ;
00338    }
00339 
00340    /*-- close file and return the empty dataset */
00341 
00342    nc_close(ncid) ; RETURN(dset) ;
00343 }

THD_3dim_dataset* THD_open_mpeg char *    hname
 

Open an MPEG file as an unpopulated AFNI dataset. It will be populated in THD_load_mpeg(). -------------------------------------------------------------------

Definition at line 13 of file thd_mpegread.c.

References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, ANAT_EPI_TYPE, ANAT_MRAN_TYPE, THD_diskptr::brick_name, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, DESTROY_IMARR, THD_datablock::diskptr, dt, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, getenv(), HEAD_ANAT_TYPE, THD_3dim_dataset::idcode, THD_ivec3::ijk, IMARR_COUNT, IMARR_SUBIM, MRI_IMAGE::kind, MCW_hash_idcode(), MCW_strncpy, mri_read_mpeg(), MRI_IMAGE::nx, MRI_IMAGE::ny, nz, OR3OK, ORCODE, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, RETURN, STORAGE_BY_MPEG, THD_diskptr::storage_mode, MCW_idcode::str, THD_MAX_PREFIX, THD_trailname(), UNITS_SEC_TYPE, VIEW_ORIGINAL_TYPE, and THD_fvec3::xyz.

Referenced by THD_init_session(), and THD_open_one_dataset().

00014 {
00015    int nim , ii , datum_type ;
00016    MRI_IMARR *imar ;
00017    MRI_IMAGE *im ;
00018    char *eee ;
00019    THD_3dim_dataset *dset=NULL ;
00020    char prefix[THD_MAX_PREFIX] , *ppp ;
00021    THD_ivec3 nxyz , orixyz ;
00022    THD_fvec3 dxyz , orgxyz ;
00023    int iview ;
00024    int   nx,ny,nz,nt ;
00025    float dx,dy,dz,dt ;
00026 
00027 
00028 ENTRY("THD_open_mpeg") ;
00029 
00030    /*-- count slices in the file --*/
00031 
00032    imar = mri_read_mpeg( hname ) ;
00033    if( imar == NULL ) RETURN(NULL) ;
00034    nim = IMARR_COUNT(imar) ;
00035 
00036    /*-- get data type for each voxel --*/
00037 
00038    im         = IMARR_SUBIM(imar,0) ;
00039    datum_type = im->kind ;
00040 
00041    /*-- compute dimensions of images, and number of images --*/
00042 
00043    nx = im->nx ;
00044    ny = im->ny ;
00045    DESTROY_IMARR(imar) ;
00046    if( nx < 2 || ny < 2 ) RETURN(NULL) ;
00047 
00048    eee = getenv("AFNI_MPEG_DATASETS") ;
00049    if( eee == NULL ) eee = "SPACE" ;
00050    switch( toupper(*eee) ){
00051      default:
00052      case 'T': nz = 1   ; nt = nim ; break ;
00053      case 'S': nz = nim ; nt = 1   ; break ;
00054    }
00055 
00056    /*-- voxel sizes --*/
00057 
00058    dx = dy = dz = dt = 1.0 ;
00059 
00060    /*-- make a dataset --*/
00061 
00062    dset = EDIT_empty_copy(NULL) ;
00063 
00064    dset->idcode.str[0] = 'M' ;  /* overwrite 1st 3 bytes */
00065    dset->idcode.str[1] = 'P' ;
00066    dset->idcode.str[2] = 'G' ;
00067 
00068    MCW_hash_idcode( hname , dset ) ;  /* 06 May 2005 */
00069 
00070    ppp = THD_trailname(hname,0) ;                   /* strip directory */
00071    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;   /* to make prefix */
00072 
00073    nxyz.ijk[0] = nx ; dxyz.xyz[0] = dx ;  /* setup axes lengths and voxel sizes */
00074    nxyz.ijk[1] = ny ; dxyz.xyz[1] = dy ;
00075    nxyz.ijk[2] = nz ; dxyz.xyz[2] = dz ;
00076 
00077    /*-- set orientation --*/
00078 
00079    { char *ori = "LAI" ;
00080      int oxx,oyy,ozz ;
00081      if( ori == NULL || strlen(ori) < 3 ) ori = "LAI"; /* set default LPI */
00082 
00083      oxx = ORCODE(ori[0]); oyy = ORCODE(ori[1]); ozz = ORCODE(ori[2]);
00084      if( !OR3OK(oxx,oyy,ozz) ){
00085        oxx = ORI_L2R_TYPE; oyy = ORI_A2P_TYPE; ozz = ORI_I2S_TYPE; /* LAI? */
00086      }
00087 
00088      orixyz.ijk[0] = oxx ;
00089      orixyz.ijk[1] = oyy ;
00090      orixyz.ijk[2] = ozz ;
00091    }
00092 
00093    /*-- origin of coordinates --*/
00094 
00095    orgxyz.xyz[0] = -0.5 * (nx-1) * dx ;
00096    orgxyz.xyz[1] = -0.5 * (ny-1) * dy ;
00097    orgxyz.xyz[2] = -0.5 * (nz-1) * dz ;
00098 
00099    iview = VIEW_ORIGINAL_TYPE ;
00100 
00101    /* 10 Oct 2002: change voxel size signs, if axis orientation is negative */
00102    /*              [above, we assumed that axes were oriented in - to + way] */
00103 
00104    if( ORIENT_sign[orixyz.ijk[0]] == '-' ){
00105      dxyz.xyz[0]   = -dxyz.xyz[0]   ;
00106      orgxyz.xyz[0] = -orgxyz.xyz[0] ;
00107    }
00108 
00109    if( ORIENT_sign[orixyz.ijk[1]] == '-' ){
00110      dxyz.xyz[1]   = -dxyz.xyz[1]   ;
00111      orgxyz.xyz[1] = -orgxyz.xyz[1] ;
00112    }
00113 
00114    if( ORIENT_sign[orixyz.ijk[2]] == '-' ){
00115      dxyz.xyz[2]   = -dxyz.xyz[2]   ;
00116      orgxyz.xyz[2] = -orgxyz.xyz[2] ;
00117    }
00118 
00119    /*-- actually send the values above into the dataset header --*/
00120 
00121    EDIT_dset_items( dset ,
00122                       ADN_prefix      , prefix ,
00123                       ADN_datum_all   , datum_type ,
00124                       ADN_nxyz        , nxyz ,
00125                       ADN_xyzdel      , dxyz ,
00126                       ADN_xyzorg      , orgxyz ,
00127                       ADN_xyzorient   , orixyz ,
00128                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00129                       ADN_nvals       , nt ,
00130                       ADN_type        , HEAD_ANAT_TYPE ,
00131                       ADN_view_type   , iview ,
00132                       ADN_func_type   , ANAT_MRAN_TYPE ,
00133                     ADN_none ) ;
00134 
00135    if( nt > 1 )              /** pretend it is 3D+time **/
00136       EDIT_dset_items( dset ,
00137                          ADN_func_type, ANAT_EPI_TYPE ,
00138                          ADN_ntt      , nt ,
00139                          ADN_ttorg    , 0.0 ,
00140                          ADN_ttdel    , dt ,
00141                          ADN_ttdur    , 0.0 ,
00142                          ADN_tunits   , UNITS_SEC_TYPE ,
00143                        ADN_none ) ;
00144 
00145    /*-- flag to read data from disk using MPEG mode --*/
00146 
00147    dset->dblk->diskptr->storage_mode = STORAGE_BY_MPEG ;
00148    strcpy( dset->dblk->diskptr->brick_name , hname ) ;
00149 
00150    RETURN(dset) ;
00151 }

THD_3dim_dataset* THD_open_nifti char *    pathname
 

will include nifti1.h *

Definition at line 12 of file thd_niftiread.c.

References ADN_datum_all, ADN_dz_sl, ADN_func_type, ADN_malloc_type, ADN_none, ADN_nsl, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_toff_sl, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, ADN_zorg_sl, ANAT_BUCK_TYPE, ANAT_EPI_TYPE, THD_diskptr::brick_name, THD_diskptr::byte_order, calloc, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, THD_datablock::diskptr, EDIT_BRICK_LABEL, EDIT_dset_items(), EDIT_empty_copy(), EDIT_STATAUX4, ENTRY, free, FUNC_BUCK_TYPE, FUNC_FIM_TYPE, HEAD_ANAT_TYPE, HEAD_FUNC_TYPE, THD_3dim_dataset::idcode, THD_ivec3::ijk, LOAD_FVEC3, LOAD_IVEC3, LOAD_MAT, MAX, MCW_hash_idcode(), MCW_IDSIZE, MCW_strncpy, my_getenv(), NI_group::name, NI_element_type(), NI_free, NI_free_element(), NI_get_attribute(), NI_GROUP_TYPE, NI_read_element(), NI_search_group_deep(), NI_stream_close(), NI_stream_open(), NI_stream_setbuf(), RETURN, STORAGE_BY_NIFTI, THD_diskptr::storage_mode, MCW_idcode::str, THD_datablock_apply_atr(), THD_dblkatr_from_niml(), THD_matrix_to_orientation(), THD_MAX_PREFIX, THD_trailname(), UNITS_SEC_TYPE, VIEW_ORIGINAL_TYPE, VIEW_TALAIRACH_TYPE, THD_fvec3::xyz, and zmax.

Referenced by THD_init_session(), THD_open_analyze(), and THD_open_one_dataset().

00013 {
00014    THD_3dim_dataset *dset=NULL ;
00015    nifti_image *nim ;
00016    int ntt , nbuc , nvals ;
00017    int use_qform = 0 , use_sform = 0 ;
00018    int statcode = 0 , datum , iview , ibr ;
00019    THD_ivec3 orixyz , nxyz ;
00020    THD_fvec3 dxyz , orgxyz ;
00021    THD_mat33 R ;
00022    char *ppp , prefix[THD_MAX_PREFIX] ;
00023 
00024 ENTRY("THD_open_nifti") ;
00025 
00026    /*-- open input file --*/
00027 
00028    { /* set the nifti_io debug level       8 Apr 2005 [rickr] */
00029       char * ept = my_getenv("AFNI_NIFTI_DEBUG");
00030       if( ept != NULL ) nifti_set_debug_level(atoi(ept));
00031    }
00032 
00033    nim = nifti_image_read( pathname, 0 ) ;
00034 
00035    if( nim == NULL || nim->nifti_type == 0 ) RETURN(NULL) ;
00036 
00037    /*-- extract some useful AFNI-ish information from the nim struct --*/
00038 
00039    /* we must have at least 2 spatial dimensions */
00040 
00041    if( nim->nx < 2 || nim->ny < 2 ) RETURN(NULL) ;
00042 
00043    /* 4th dimension = time; 5th dimension = bucket:
00044       these are mutually exclusive in AFNI at present */
00045 
00046    ntt = nim->nt ; nbuc = nim->nu ;
00047    if( ntt > 1 && nbuc > 1 ){
00048      fprintf(stderr,
00049              "** AFNI can't deal with 5 dimensional NIfTI dataset file %s\n",
00050              pathname ) ;
00051      RETURN(NULL) ;
00052    }
00053    nvals = MAX(ntt,nbuc) ;
00054 
00055    /* determine type of dataset values:
00056       if we are scaling, or if the data type in the NIfTI file
00057       is something AFNI can't handle, then the result will be floats */
00058 
00059    switch( nim->datatype ){
00060      default:
00061        fprintf(stderr,
00062                "** AFNI can't handle NIFTI datatype=%d (%s) in file %s\n",
00063                nim->datatype, nifti_datatype_string(nim->datatype), pathname );
00064        RETURN(NULL) ;
00065      break ;
00066 
00067      case DT_UINT8:     datum = (nim->scl_slope != 0.0) ? MRI_float : MRI_byte  ; break ;
00068      case DT_INT16:     datum = (nim->scl_slope != 0.0) ? MRI_float : MRI_short ; break ;
00069 
00070      case DT_FLOAT32:   datum = MRI_float   ; break ;
00071      case DT_COMPLEX64: datum = MRI_complex ; break ;
00072      case DT_RGB24:     datum = MRI_rgb     ; break ;
00073 
00074      case DT_INT8:      /* NIfTI-1 data types that AFNI can't handle directly */
00075      case DT_UINT16:
00076      case DT_INT32:
00077      case DT_UINT32:
00078      case DT_FLOAT64:
00079        fprintf(stderr,
00080               "** AFNI converts NIFTI_datatype=%d (%s) in file %s to FLOAT32\n",
00081               nim->datatype, nifti_datatype_string(nim->datatype), pathname );
00082        datum = MRI_float ;
00083      break ;
00084 
00085 #if 0
00086      case DT_COMPLEX128:  /* this case would be too much like real work */
00087        fprintf(stderr,
00088                "** AFNI convert NIFTI_datatype=%d (%s) in file %s to COMPLEX64\n",
00089                nim->datatype, nifti_datatype_string(nim->datatype), pathname );
00090        datum = MRI_complex ;
00091      break ;
00092 #endif
00093    }
00094 
00095    /* check for statistics code */
00096 
00097    if( nim->intent_code >= NIFTI_FIRST_STATCODE &&
00098        nim->intent_code <= NIFTI_LAST_STATCODE    ){
00099 
00100      if( nim->intent_code > FUNC_PT_TYPE ){
00101        fprintf(stderr,
00102                "** AFNI doesn't understand NIFTI statistic type %d (%s) in file %s\n",
00103                nim->intent_code , nifti_intent_string(nim->intent_code) , pathname ) ;
00104      } else {
00105        statcode = nim->intent_code ;
00106        if( nbuc > 1 ){
00107          fprintf(stderr,
00108                  "** AFNI doesn't support NIFTI voxel-dependent statistic parameters"
00109                  " in file %s\n" , pathname ) ;
00110          statcode = 0 ;
00111        }
00112      }
00113    }
00114 
00115 
00116   /* KRH 07/11/05 -- adding ability to choose spatial transform
00117       from the options of qform, sform, bothform, or noform.
00118 
00119      If qform is present, it will be used.
00120 
00121      If qform is absent, but sform present, then the sform
00122        will be modified to be an orthogonal rotation and used.
00123 
00124      If both qform and sform are absent, then we will have
00125        an error.
00126 
00127      Previously assumed qform present.  */
00128 
00129    if ((nim->qform_code > 0) && (nim->sform_code > 0) ) {
00130      use_qform = 1 ;
00131      use_sform = 0 ;
00132    } else if (nim->qform_code > 0) {
00133      use_qform = 1 ;
00134      use_sform = 0 ;
00135    } else if (nim->sform_code > 0) { 
00136      use_qform = 0 ;
00137      use_sform = 1 ;
00138    } else {
00139      use_qform = 0 ;
00140      use_sform = 0 ;
00141      fprintf(stderr,
00142              "** NO spatial transform (neither preferred qform nor sform), in NIfTI dataset file:\n %s\nUsing senseless defaults.\n",
00143              pathname ) ;
00144    }
00145 
00146 
00147    if (use_qform) {
00148 
00149      float orgx, orgy, orgz ;
00150 
00151      /* determine orientation from the qto_xyz matrix,
00152       which transforms (i,j,k) voxel indexes to (x,y,z) LPI coordinates */
00153 
00154      LOAD_MAT(R, -nim->qto_xyz.m[0][0] ,  /* negate x and y   */
00155                  -nim->qto_xyz.m[0][1] ,  /* coefficients,    */
00156                  -nim->qto_xyz.m[0][2] ,  /* since AFNI works */
00157                  -nim->qto_xyz.m[1][0] ,  /* with RAI coords, */
00158                  -nim->qto_xyz.m[1][1] ,  /* but NIFTI uses   */
00159                  -nim->qto_xyz.m[1][2] ,  /* LPI coordinates. */
00160                   nim->qto_xyz.m[2][0] ,  /* [Which is my own] */
00161                   nim->qto_xyz.m[2][1] ,  /* [damn fault!!!!!] */
00162                   nim->qto_xyz.m[2][2]  ) ;
00163 
00164      orixyz = THD_matrix_to_orientation( R ) ;   /* compute orientation codes */
00165    
00166      iview = ((nim->qform_code == NIFTI_XFORM_TALAIRACH ) ||
00167               (nim->qform_code == NIFTI_XFORM_MNI_152 ))
00168              ? VIEW_TALAIRACH_TYPE : VIEW_ORIGINAL_TYPE ;
00169 
00170 
00171      /* load the offsets and the grid spacings */
00172 
00173      if (ORIENT_xyz[orixyz.ijk[0]] == 'z' )  {
00174        orgx = nim->qto_xyz.m[ORIENT_xyzint[orixyz.ijk[0]] - 1][3] ;
00175      } else {
00176        orgx = - nim->qto_xyz.m[ORIENT_xyzint[orixyz.ijk[0]] - 1][3] ;
00177      }
00178 
00179      if (ORIENT_xyz[orixyz.ijk[1]] == 'z' )  {
00180        orgy = nim->qto_xyz.m[ORIENT_xyzint[orixyz.ijk[1]] - 1][3] ;
00181      } else {
00182        orgy = - nim->qto_xyz.m[ORIENT_xyzint[orixyz.ijk[1]] - 1][3] ;
00183      }
00184 
00185      if (ORIENT_xyz[orixyz.ijk[2]] == 'z' )  {
00186        orgz = nim->qto_xyz.m[ORIENT_xyzint[orixyz.ijk[2]] - 1][3] ;
00187      } else {
00188        orgz = - nim->qto_xyz.m[ORIENT_xyzint[orixyz.ijk[2]] - 1][3] ;
00189      }
00190 
00191 
00192      LOAD_FVEC3( orgxyz ,  orgx ,
00193                            orgy ,
00194                            orgz  ) ;
00195 #if 0
00196      LOAD_FVEC3( orgxyz , -nim->qto_xyz.m[0][3] ,    /* again, negate  */
00197                         -nim->qto_xyz.m[1][3] ,    /* x and y coords */
00198                          nim->qto_xyz.m[2][3]  ) ;
00199 #endif
00200 
00201      /* AFNI space units are always mm */
00202 
00203      if( nim->xyz_units == NIFTI_UNITS_METER ){
00204        nim->dx *= 1000.0 ; nim->dy *= 1000.0 ; nim->dz *= 1000.0 ;
00205      } else if(  nim->xyz_units == NIFTI_UNITS_MICRON ){
00206        nim->dx *= 0.001  ; nim->dy *= 0.001  ; nim->dz *= 0.001  ;
00207      }
00208 
00209      LOAD_FVEC3( dxyz , (ORIENT_sign[orixyz.ijk[0]]=='+') ? nim->dx : -nim->dx ,
00210                         (ORIENT_sign[orixyz.ijk[1]]=='+') ? nim->dy : -nim->dy ,
00211                         (ORIENT_sign[orixyz.ijk[2]]=='+') ? nim->dz : -nim->dz  ) ;
00212 
00213    } else if (use_sform) {
00214 
00215      int orimap[7] = { 6 , 1 , 0 , 2 , 3 , 4 , 5 } ;
00216      int oritmp[3] ;
00217      float dxtmp, dytmp, dztmp ;
00218      float xmax, ymax, zmax ;
00219      float orgx, orgy, orgz ;
00220      float fig_merit, ang_merit ;
00221 
00222      /* convert sform to nifti orientation codes */
00223 
00224      nifti_mat44_to_orientation(nim->sto_xyz, &oritmp[0], &oritmp[1], &oritmp[2] ) ;
00225 
00226      /* convert nifti orientation codes to AFNI codes and store in vector */
00227 
00228      LOAD_IVEC3( orixyz , orimap[oritmp[0]] ,
00229                           orimap[oritmp[1]] ,
00230                           orimap[oritmp[2]] ) ;
00231 
00232      /* assume original view if there's no talairach id present */
00233 
00234      iview = ((nim->sform_code == NIFTI_XFORM_TALAIRACH ) ||
00235               (nim->sform_code == NIFTI_XFORM_MNI_152 ))
00236              ? VIEW_TALAIRACH_TYPE : VIEW_ORIGINAL_TYPE ;
00237 
00238      /* load the offsets and the grid spacings */
00239 
00240      if (ORIENT_xyz[orixyz.ijk[0]] == 'z' )  {
00241        orgx = nim->sto_xyz.m[ORIENT_xyzint[orixyz.ijk[0]] - 1][3] ;
00242      } else {
00243        orgx = - nim->sto_xyz.m[ORIENT_xyzint[orixyz.ijk[0]] - 1][3] ;
00244      }
00245 
00246      if (ORIENT_xyz[orixyz.ijk[1]] == 'z' )  {
00247        orgy = nim->sto_xyz.m[ORIENT_xyzint[orixyz.ijk[1]] - 1][3] ;
00248      } else {
00249        orgy = - nim->sto_xyz.m[ORIENT_xyzint[orixyz.ijk[1]] - 1][3] ;
00250      }
00251 
00252      if (ORIENT_xyz[orixyz.ijk[2]] == 'z' )  {
00253        orgz = nim->sto_xyz.m[ORIENT_xyzint[orixyz.ijk[2]] - 1][3] ;
00254      } else {
00255        orgz = - nim->sto_xyz.m[ORIENT_xyzint[orixyz.ijk[2]] - 1][3] ;
00256      }
00257 
00258 
00259      LOAD_FVEC3( orgxyz ,  orgx ,
00260                            orgy ,
00261                            orgz  ) ;
00262 
00263 #if 0
00264      LOAD_FVEC3( orgxyz , -nim->sto_xyz.m[0][3] ,    /* again, negate  */
00265                           -nim->sto_xyz.m[1][3] ,    /* x and y coords */
00266                            nim->sto_xyz.m[2][3] ) ;
00267 #endif
00268 
00269 #define MAXNUM(a,b) ( (a) > (b) ? (a):(b))
00270 #define MAX3(a,b,c) ( (MAXNUM(a,b)) > (MAXNUM(a,c)) ? (MAXNUM(a,b)):(MAXNUM(a,c)))
00271 #define MINNUM(a,b) ( (a) < (b) ? (a):(b))
00272 #define MIN3(a,b,c) ( (MINNUM(a,b)) < (MINNUM(a,c)) ? (MINNUM(a,b)):(MINNUM(a,c)))
00273 
00274      dxtmp = sqrt ( nim->sto_xyz.m[0][0] * nim->sto_xyz.m[0][0] +
00275                     nim->sto_xyz.m[1][0] * nim->sto_xyz.m[1][0] +
00276                     nim->sto_xyz.m[2][0] * nim->sto_xyz.m[2][0] ) ;
00277 
00278      xmax = MAX3(fabs(nim->sto_xyz.m[0][0]),fabs(nim->sto_xyz.m[1][0]),fabs(nim->sto_xyz.m[2][0])) / dxtmp ;
00279  
00280      dytmp = sqrt ( nim->sto_xyz.m[0][1] * nim->sto_xyz.m[0][1] +
00281                     nim->sto_xyz.m[1][1] * nim->sto_xyz.m[1][1] +
00282                     nim->sto_xyz.m[2][1] * nim->sto_xyz.m[2][1] ) ;
00283  
00284      ymax = MAX3(fabs(nim->sto_xyz.m[0][1]),fabs(nim->sto_xyz.m[1][1]),fabs(nim->sto_xyz.m[2][1])) / dytmp ;
00285 
00286      dztmp = sqrt ( nim->sto_xyz.m[0][2] * nim->sto_xyz.m[0][2] +
00287                     nim->sto_xyz.m[1][2] * nim->sto_xyz.m[1][2] +
00288                     nim->sto_xyz.m[2][2] * nim->sto_xyz.m[2][2] ) ;
00289 
00290      zmax = MAX3(fabs(nim->sto_xyz.m[0][2]),fabs(nim->sto_xyz.m[1][2]),fabs(nim->sto_xyz.m[2][2])) / dztmp ;
00291 
00292      fig_merit = MIN3(xmax,ymax,zmax) ;
00293      ang_merit = acos (fig_merit) * 180.0 / 3.141592653 ;
00294 
00295      if (fabs(ang_merit) > .01) {
00296        fprintf(stderr, "qform not present, sform used.\n"
00297                        "sform was not exact, and the worst axis is\n"
00298                        "%f degrees from plumb.\n",ang_merit ) ;
00299      }
00300 
00301      if( nim->xyz_units == NIFTI_UNITS_METER ){
00302        dxtmp *= 1000.0 ; dytmp *= 1000.0 ; dztmp *= 1000.0 ;
00303      } else if(  nim->xyz_units == NIFTI_UNITS_MICRON ){
00304        dxtmp *= 0.001  ; dytmp *= 0.001  ; dztmp *= 0.001  ;
00305      }
00306 
00307      LOAD_FVEC3( dxyz , (ORIENT_sign[orixyz.ijk[0]]=='+') ? dxtmp : -dxtmp ,
00308                         (ORIENT_sign[orixyz.ijk[1]]=='+') ? dytmp : -dytmp ,
00309                         (ORIENT_sign[orixyz.ijk[2]]=='+') ? dztmp : -dztmp ) ;
00310 
00311    } else { /* NO SPATIAL XFORM. BAD BAD BAD BAD BAD BAD. */
00312 
00313      float dxtmp, dytmp, dztmp ;
00314 
00315      /* if pixdim data are present, use them in order to set pixel 
00316         dimensions.  otherwise, set the dimensions to 1 unit.         */ 
00317 
00318      dxtmp = ((nim->pixdim[1] > 0) ? nim->pixdim[1] : 1) ;
00319      dytmp = ((nim->pixdim[2] > 0) ? nim->pixdim[2] : 1) ;
00320      dztmp = ((nim->pixdim[3] > 0) ? nim->pixdim[3] : 1) ;
00321 
00322      if( nim->xyz_units == NIFTI_UNITS_METER ){
00323        dxtmp *= 1000.0 ; dytmp *= 1000.0 ; dztmp *= 1000.0 ;
00324      } else if(  nim->xyz_units == NIFTI_UNITS_MICRON ){
00325        dxtmp *= 0.001  ; dytmp *= 0.001  ; dztmp *= 0.001  ;
00326      }
00327 
00328      /* set orientation to LPI by default    */
00329 
00330      LOAD_IVEC3( orixyz , 1 ,
00331                           2 ,
00332                           4 ) ;
00333 
00334      LOAD_FVEC3( dxyz , (ORIENT_sign[orixyz.ijk[0]]=='+') ? dxtmp : -dxtmp ,
00335                         (ORIENT_sign[orixyz.ijk[1]]=='+') ? dytmp : -dytmp ,
00336                         (ORIENT_sign[orixyz.ijk[2]]=='+') ? dztmp : -dztmp ) ;
00337 
00338      iview = VIEW_ORIGINAL_TYPE ;
00339 
00340      /* set origin to 0,0,0   */
00341 
00342      LOAD_FVEC3( orgxyz , 0 ,
00343                           0 ,
00344                           0 ) ;
00345    }
00346 
00347 
00348    /*-- make an AFNI dataset! --*/
00349 
00350    dset = EDIT_empty_copy(NULL) ;
00351 
00352    ppp  = THD_trailname(pathname,0) ;               /* strip directory */
00353    MCW_strncpy( prefix , ppp , THD_MAX_PREFIX ) ;   /* to make prefix */
00354 
00355    nxyz.ijk[0] = nim->nx ;                          /* grid dimensions */
00356    nxyz.ijk[1] = nim->ny ;
00357    nxyz.ijk[2] = nim->nz ;
00358 
00359    dset->idcode.str[0] = 'N' ;  /* overwrite 1st 3 bytes with something special */
00360    dset->idcode.str[1] = 'I' ;
00361    dset->idcode.str[2] = 'I' ;
00362 
00363    MCW_hash_idcode( pathname , dset ) ;  /* 06 May 2005 */
00364 
00365    EDIT_dset_items( dset ,
00366                       ADN_prefix      , prefix ,
00367                       ADN_datum_all   , datum ,
00368                       ADN_nxyz        , nxyz ,
00369                       ADN_xyzdel      , dxyz ,
00370                       ADN_xyzorg      , orgxyz ,
00371                       ADN_xyzorient   , orixyz ,
00372                       ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00373                       ADN_view_type   , iview ,
00374                       ADN_type        , (statcode != 0) ? HEAD_FUNC_TYPE
00375                                                         : HEAD_ANAT_TYPE ,
00376                     ADN_none ) ;
00377 
00378    /* not a time dependent dataset */
00379 
00380    if( ntt < 2 ){
00381      EDIT_dset_items( dset ,
00382                         ADN_nvals     , nbuc ,
00383                         ADN_datum_all , datum ,
00384                         ADN_func_type , (statcode != 0) ? FUNC_BUCK_TYPE
00385                                                         : ANAT_BUCK_TYPE ,
00386                       ADN_none ) ;
00387 
00388    } else {  /* is a time dependent dataset */
00389 
00390           if( nim->time_units == NIFTI_UNITS_MSEC ) nim->dt *= 0.001 ;
00391      else if( nim->time_units == NIFTI_UNITS_USEC ) nim->dt *= 1.e-6 ;
00392      EDIT_dset_items( dset ,
00393                         ADN_nvals     , ntt ,
00394                         ADN_ntt       , ntt ,
00395                         ADN_datum_all , datum ,
00396                         ADN_ttorg     , 0.0 ,
00397                         ADN_ttdel     , nim->dt ,
00398                         ADN_ttdur     , 0.0 ,
00399                         ADN_tunits    , UNITS_SEC_TYPE ,
00400                         ADN_func_type , (statcode != 0) ? FUNC_FIM_TYPE
00401                                                         : ANAT_EPI_TYPE ,
00402                       ADN_none ) ;
00403 
00404      /* if present, add stuff about the slice-timing offsets */
00405 
00406      if( nim->slice_dim      == 3               && /* AFNI can only deal with */
00407          nim->slice_code     >  0               && /* slice timing offsets    */
00408          nim->slice_duration >  0.0             && /* along the k-axis of     */
00409          nim->slice_start    >= 0               && /* the dataset volume      */
00410          nim->slice_start    < nim->nz          &&
00411          nim->slice_end      > nim->slice_start &&
00412          nim->slice_end      < nim->nz             ){
00413 
00414        float *toff=(float *)calloc(sizeof(float),nim->nz) , tsl ;
00415        int kk ;
00416 
00417             if( nim->time_units == NIFTI_UNITS_MSEC ) nim->slice_duration *= 0.001;
00418        else if( nim->time_units == NIFTI_UNITS_USEC ) nim->slice_duration *= 1.e-6;
00419 
00420        /* set up slice time offsets in the divers orders */
00421 
00422        switch( nim->slice_code ){
00423          case NIFTI_SLICE_SEQ_INC:
00424            tsl = 0.0 ;
00425            for( kk=nim->slice_start ; kk <= nim->slice_end ; kk++ ){
00426              toff[kk] = tsl ; tsl += nim->slice_duration ;
00427            }
00428          break ;
00429          case NIFTI_SLICE_SEQ_DEC:
00430            tsl = 0.0 ;
00431            for( kk=nim->slice_end ; kk >= nim->slice_end ; kk-- ){
00432              toff[kk] = tsl ; tsl += nim->slice_duration ;
00433            }
00434          break ;
00435          case NIFTI_SLICE_ALT_INC:
00436            tsl = 0.0 ;
00437            for( kk=nim->slice_start ; kk <= nim->slice_end ; kk+=2 ){
00438              toff[kk] = tsl ; tsl += nim->slice_duration ;
00439            }
00440            for( kk=nim->slice_start+1 ; kk <= nim->slice_end ; kk+=2 ){
00441              toff[kk] = tsl ; tsl += nim->slice_duration ;
00442            }
00443          break ;
00444          case NIFTI_SLICE_ALT_INC2:
00445            tsl = 0.0 ;
00446            for( kk=nim->slice_start+1 ; kk <= nim->slice_end ; kk+=2 ){
00447              toff[kk] = tsl ; tsl += nim->slice_duration ;
00448            }
00449            for( kk=nim->slice_start ; kk <= nim->slice_end ; kk+=2 ){
00450              toff[kk] = tsl ; tsl += nim->slice_duration ;
00451            }
00452          break ;
00453          case NIFTI_SLICE_ALT_DEC:
00454            tsl = 0.0 ;
00455            for( kk=nim->slice_end ; kk >= nim->slice_start ; kk-=2 ){
00456              toff[kk] = tsl ; tsl += nim->slice_duration ;
00457            }
00458            for( kk=nim->slice_end-1 ; kk >= nim->slice_start ; kk-=2 ){
00459              toff[kk] = tsl ; tsl += nim->slice_duration ;
00460            }
00461          break ;
00462          case NIFTI_SLICE_ALT_DEC2:
00463            tsl = 0.0 ;
00464            for( kk=nim->slice_end-1 ; kk >= nim->slice_start ; kk-=2 ){
00465              toff[kk] = tsl ; tsl += nim->slice_duration ;
00466            }
00467            for( kk=nim->slice_end ; kk >= nim->slice_start ; kk-=2 ){
00468              toff[kk] = tsl ; tsl += nim->slice_duration ;
00469            }
00470          break ;
00471        }
00472 
00473        EDIT_dset_items( dset ,
00474                           ADN_nsl     , nim->nz       ,
00475                           ADN_zorg_sl , orgxyz.xyz[2] ,
00476                           ADN_dz_sl   , dxyz.xyz[2]   ,
00477                           ADN_toff_sl , toff          ,
00478                         ADN_none ) ;
00479 
00480        free(toff) ;
00481 
00482      } /* end of slice timing stuff */
00483 
00484    } /* end of 3D+time dataset stuff */
00485 
00486    /* add statistics, if present */
00487 
00488    if( statcode != 0 ){
00489      for( ibr=0 ; ibr < nvals ; ibr++ )
00490        EDIT_STATAUX4(dset,ibr,statcode,nim->intent_p1,nim->intent_p2,nim->intent_p3,0) ;
00491    }
00492 
00493    /*-- flag to read data from disk using NIFTI functions --*/
00494 
00495    dset->dblk->diskptr->storage_mode = STORAGE_BY_NIFTI ;
00496    strcpy( dset->dblk->diskptr->brick_name , pathname ) ;
00497    dset->dblk->diskptr->byte_order = nim->byteorder ;
00498 
00499 #if 0
00500    for( ibr=0 ; ibr < nvals ; ibr++ ){     /* make sub-brick labels */
00501      sprintf(prefix,"%s[%d]",tname,ibr) ;
00502      EDIT_BRICK_LABEL( dset , ibr , prefix ) ;
00503    }
00504 #endif
00505 
00506    /** 10 May 2005: see if there is an AFNI extension;
00507                     if so, load attributes from it and
00508                     then edit the dataset appropriately **/
00509 
00510    { int ee ;  /* extension index */
00511 
00512      /* scan extension list to find the first AFNI extension */
00513 
00514      for( ee=0 ; ee < nim->num_ext ; ee++ )
00515        if( nim->ext_list[ee].ecode == NIFTI_ECODE_AFNI &&
00516            nim->ext_list[ee].esize > 32                &&
00517            nim->ext_list[ee].edata != NULL               ) break ;
00518 
00519      /* if found an AFNI extension ... */
00520 
00521      if( ee < nim->num_ext ){
00522        char *buf = nim->ext_list[ee].edata , *rhs , *cpt ;
00523        int  nbuf = nim->ext_list[ee].esize - 8 ;
00524        NI_stream ns ;
00525        void     *nini ;
00526        NI_group *ngr , *nngr ;
00527 
00528        /* if have data, it's long enough, and starts properly, then ... */
00529 
00530        if( buf != NULL && nbuf > 32 && strncmp(buf,"<?xml",5)==0 ){
00531          if( buf[nbuf-1] != '\0' ) buf[nbuf-1] = '\0' ;         /* for safety */
00532          cpt = strstr(buf,"?>") ;                    /* find XML prolog close */
00533          if( cpt != NULL ){                          /* if found it, then ... */
00534            ns = NI_stream_open( "str:" , "r" ) ;
00535            NI_stream_setbuf( ns , cpt+2 ) ;        /* start just after prolog */
00536            nini = NI_read_element(ns,1) ;                 /* get root element */
00537            NI_stream_close(ns) ;
00538            if( NI_element_type(nini) == NI_GROUP_TYPE ){   /* must be a group */
00539              ngr = (NI_group *)nini ;
00540              if( strcmp(ngr->name,"AFNI_attributes") == 0 ){    /* root is OK */
00541                nngr = ngr ;
00542              } else {                   /* search in group for proper element */
00543                int nn ; void **nnini ;
00544                nn = NI_search_group_deep( ngr , "AFNI_attributes" , &nnini ) ;
00545                if( nn <= 0 ) nngr = NULL ;
00546                else        { nngr = (NI_group *)nnini[0]; NI_free(nnini); }
00547              }
00548 
00549              if( NI_element_type(nngr) == NI_GROUP_TYPE ){ /* have  good name */
00550                rhs = NI_get_attribute( nngr , "self_idcode" ) ;
00551                if( rhs == NULL )
00552                  rhs = NI_get_attribute( nngr , "AFNI_idcode" ) ;
00553                if( rhs != NULL )    /* set dataset ID code from XML attribute */
00554                  MCW_strncpy( dset->idcode.str , rhs , MCW_IDSIZE ) ;
00555                rhs = NI_get_attribute( nngr , "NIfTI_nums" ) ;    /* check if */
00556                if( rhs != NULL ){                       /* dataset dimensions */
00557                  char buf[128] ;                              /* were altered */
00558                  sprintf(buf,"%d,%d,%d,%d,%d,%d" ,             /* 12 May 2005 */
00559                    nim->nx, nim->ny, nim->nz, nim->nt, nim->nu, nim->datatype );
00560                  if( strcmp(buf,rhs) != 0 ){
00561                    static int nnn=0 ;
00562                    if(nnn==0){fprintf(stderr,"\n"); nnn=1;}
00563                    fprintf(stderr,
00564                      "** WARNING: NIfTI file %s dimensions altered since "
00565                                  "AFNI extension was added\n",pathname ) ;
00566                  }
00567                }
00568                THD_dblkatr_from_niml( nngr , dset->dblk ); /* load attributes */
00569                THD_datablock_apply_atr( dset ) ;   /* apply to dataset struct */
00570              }
00571              NI_free_element( ngr ) ;          /* get rid of the root element */
00572 
00573            } /* end of if found a group element at the root */
00574          } /* end of if extension data array had an XML prolog close */
00575        } /* end of if had a good extension data array */
00576      } /* end of if had an AFNI extension */
00577    } /* end of processing extensions */
00578 
00579    /* return unpopulated dataset */
00580 
00581    nifti_image_free(nim) ; RETURN(dset) ;
00582 }

THD_3dim_dataset* THD_open_one_dataset char *   
 

Definition at line 23 of file thd_opendset.c.

References CHECK_FOR_DATA, DATASET_BRICK_SUFFIX, DATASET_HEADER_SUFFIX, ENTRY, getenv(), offset, RETURN, STRING_HAS_SUFFIX, THD_3dim_from_block(), THD_filesize(), THD_init_one_datablock(), THD_is_file(), THD_MAX_NAME, THD_open_1D(), THD_open_3D(), THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), THD_open_dataset(), THD_open_minc(), THD_open_mpeg(), and THD_open_nifti().

Referenced by B2F_read_opts(), BUCK_read_opts(), CALC_read_opts(), check_output_files(), get_line_opt(), get_options(), IMREG_main(), main(), output_ts_array(), read_dataset(), read_input_data(), T3D_anatomy_parent_CB(), T3D_geometry_parent_CB(), TCAT_read_opts(), THD_fetch_dataset(), THD_open_3dcalc(), THD_open_dataset(), THD_read_dvecmat(), TT_load_atlas(), VL_command_line(), write_3dtime(), write_afni_data(), write_bucket_data(), and write_ts_array().

00024 {
00025    int ii , plen ;
00026    char dirname[THD_MAX_NAME] , fullname[THD_MAX_NAME] ;
00027    THD_3dim_dataset *dset ;
00028    THD_datablock    *dblk ;
00029    char *sub ;
00030    char *fname ;   /* to skip directory during HEAD/BRIK search in filename */
00031    int   offset ;  /*                                 - [rickr 20 Sep 2002] */
00032    int fsize ;     /* 06 Jan 2005 */
00033 
00034 ENTRY("THD_open_one_dataset") ;
00035 
00036    /*-- sanity check --*/
00037 
00038    if( pathname == NULL              ||
00039        (plen=strlen(pathname)) == 0  ||
00040        pathname[plen-1]        == '/'  ) RETURN(NULL) ;
00041 
00042    /*-- perhaps open the new-fangled way [22 May 2000] --*/
00043 
00044    if( getenv("AFNI_USE_THD_open_dataset") != NULL &&
00045        strstr(pathname,"[")                != NULL   ){
00046 
00047       RETURN( THD_open_dataset(pathname) ) ;
00048    }
00049 
00050    fsize = THD_filesize(pathname) ;                         /* 06 Jan 2005 */
00051    if( fsize == 0 && !THD_is_file(pathname) ) fsize = -1 ;  /* 31 Mar 2005 */
00052 
00053    /*-- perhaps the MINC way --*/
00054 
00055    if( STRING_HAS_SUFFIX(pathname,".mnc") ){
00056      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00057      RETURN( THD_open_minc(pathname) ) ;
00058    }
00059 
00060    /*-- perhaps the ANALYZE way --*/
00061 
00062    if( STRING_HAS_SUFFIX(pathname,".hdr") ){
00063      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00064      RETURN( THD_open_analyze(pathname) ) ;
00065    }
00066 
00067    /*-- perhaps the CTF way [04 Dec 2002] --*/
00068 
00069    if( STRING_HAS_SUFFIX(pathname,".mri") ){
00070      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00071      RETURN( THD_open_ctfmri(pathname) ) ;
00072    } else if( STRING_HAS_SUFFIX(pathname,".svl") ){
00073      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00074      RETURN( THD_open_ctfsam(pathname) ) ;
00075    }
00076 
00077    /*-- 04 Mar 2003: allow input of .1D files --*/
00078 
00079    if( STRING_HAS_SUFFIX(pathname,".1D") ){
00080      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00081      RETURN( THD_open_1D(pathname) ) ;
00082    } else if( STRING_HAS_SUFFIX(pathname,".3D") ){  /* 21 Mar 2003 */
00083      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00084      RETURN( THD_open_3D(pathname) ) ;
00085    }
00086 
00087    /*-- 28 Aug 2003: the NIFTI way! --*/
00088 
00089    if( STRING_HAS_SUFFIX(pathname,".nii")    ||
00090        STRING_HAS_SUFFIX(pathname,".nii.gz") ||
00091        STRING_HAS_SUFFIX(pathname,".nia")      ){
00092 
00093      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00094      RETURN( THD_open_nifti(pathname) ) ;
00095    }
00096 
00097    /*-- 03 Dec 2003: the MPEG way! --*/
00098 
00099    if( STRING_HAS_SUFFIX(pathname,".mpg")  ||
00100        STRING_HAS_SUFFIX(pathname,".MPG")  ||
00101        STRING_HAS_SUFFIX(pathname,".MPEG") ||
00102        STRING_HAS_SUFFIX(pathname,".mpeg")   ){
00103 
00104      CHECK_FOR_DATA(pathname) ;               /* 06 Jan 2005 */
00105      RETURN( THD_open_mpeg(pathname) ) ;
00106    }
00107 
00108    /*-- Must be an AFNI-formatted dataset! -------------*/
00109    /*-- find directory and last names in the pathname --*/
00110 
00111    for( ii=plen-1 ; ii >= 0 ; ii-- ) if( pathname[ii] == '/' ) break ;
00112 
00113    if( ii < 0 ){
00114      strcpy( dirname , "./" ) ;      /* fake directory name */
00115    } else {
00116      strcpy( dirname , pathname ) ;
00117      dirname[ii+1] = '\0' ;
00118    }
00119    offset = ii + 1 ;  /* offset of file within pathname - rickr [20 Sep 2002] */
00120 
00121    /*-- perform surgery on the name to make it a valid .HEAD --*/
00122 
00123    strcpy( fullname , pathname ) ;
00124    fname = fullname + offset ; /* trailing filename (past directory) - rickr */
00125 
00126    /* (REPLACE) sub = strstr( fullname , DATASET_HEADER_SUFFIX ) ;  * .HEAD ? */
00127    sub = strstr( fname , DATASET_HEADER_SUFFIX ) ;   /* .HEAD ?  r:fname */
00128 
00129    if( sub == NULL ){                                   /* no! */
00130       sub = strstr( fname , DATASET_BRICK_SUFFIX ) ; /* .BRIK ?  r:fname */
00131 
00132       if( sub == NULL ){                               /* no! */
00133          ii = strlen(fullname) ;
00134          if( fullname[ii-1] != '.' ) strcat( fullname , "." ) ; /* tack .HEAD */
00135          strcat( fullname , DATASET_HEADER_SUFFIX ) ;           /* onto end */
00136 
00137       } else {                                     /* yes! */
00138          strcpy( sub , DATASET_HEADER_SUFFIX ) ;   /* replace .BRIK with .HEAD */
00139       }
00140    }
00141 
00142    /*-- open it up? --*/
00143 
00144    fsize = THD_filesize(fullname) ;                         /* 06 Jan 2005 */
00145    if( fsize == 0 && !THD_is_file(pathname) ) fsize = -1 ;  /* 31 Mar 2005 */
00146    CHECK_FOR_DATA(fullname) ;
00147 
00148    dblk = THD_init_one_datablock( dirname , fullname ) ;
00149    if( dblk == NULL ) RETURN(NULL) ;
00150 
00151    dset = THD_3dim_from_block( dblk ) ;
00152    RETURN(dset) ;
00153 }

THD_3dim_dataset* THD_open_tcat char *    dlist
 

Open a dataset that is an impromptu catenation of multiple dataset.

Definition at line 7 of file thd_opentcat.c.

References ADN_func_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ANAT_EPI_TYPE, DSET_delete, DSET_mallocize, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_TIMESTEP, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, EQUIV_DATAXES, free, FUNC_FIM_TYPE, ISANAT, malloc, NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, RETURN, NI_str_array::str, THD_3dim_dataset::tcat_len, THD_3dim_dataset::tcat_list, THD_3dim_dataset::tcat_num, THD_open_dataset(), TR, and UNITS_SEC_TYPE.

Referenced by THD_open_dataset().

00008 {
00009    THD_3dim_dataset *dset_out , **dset_in ;
00010    int ndset_in , dd , nerr , new_nvals ;
00011    NI_str_array *sar ;
00012 
00013 ENTRY("THD_open_tcat") ;
00014 
00015    if( dlist == NULL || *dlist == '\0' ) RETURN(NULL) ;
00016 
00017    if( strchr(dlist,' ') == NULL ){
00018      dset_out = THD_open_dataset(dlist) ; RETURN(dset_out) ;
00019    }
00020 
00021    sar = NI_decode_string_list( dlist , "~" ) ;
00022    if( sar == NULL ) RETURN(NULL) ;
00023 
00024    ndset_in = sar->num ;
00025    dset_in  = (THD_3dim_dataset **)malloc(sizeof(THD_3dim_dataset *)*sar->num) ;
00026    for( nerr=dd=0 ; dd < ndset_in ; dd++ ){
00027      dset_in[dd] = THD_open_dataset( sar->str[dd] ) ;
00028      if( dset_in[dd] == NULL ){
00029        fprintf(stderr,"** THD_open_tcat: can't open dataset %s\n",sar->str[dd]) ;
00030        nerr++ ;
00031      }
00032    }
00033    if( nerr > 0 ){
00034      for( dd=0 ; dd < ndset_in ; dd++ )
00035        if( dset_in[dd] != NULL ) DSET_delete(dset_in[dd]) ;
00036      free((void *)dset_in) ;
00037      NI_delete_str_array(sar) ;
00038      RETURN(NULL) ;
00039    }
00040    if( ndset_in == 1 ){
00041      dset_out = dset_in[0] ;
00042      free((void *)dset_in) ;
00043      NI_delete_str_array(sar) ;
00044      RETURN(dset_out) ;
00045    }
00046 
00047    for( nerr=0,dd=1 ; dd < ndset_in ; dd++ ){
00048      if( DSET_NX(dset_in[0]) != DSET_NX(dset_in[dd]) ||
00049          DSET_NY(dset_in[0]) != DSET_NY(dset_in[dd]) ||
00050          DSET_NZ(dset_in[0]) != DSET_NZ(dset_in[dd])   ){
00051        fprintf(stderr,
00052                "** THD_open_tcat: %s [%dx%dx%d] doesn't match %s [%dx%dx%d]\n",
00053                sar->str[0] ,DSET_NX(dset_in[0]) ,
00054                             DSET_NY(dset_in[0]) ,DSET_NZ(dset_in[0]) ,
00055                sar->str[dd],DSET_NX(dset_in[dd]),
00056                             DSET_NY(dset_in[dd]),DSET_NZ(dset_in[dd]) ) ;
00057        nerr++ ;
00058      } else if( !EQUIV_DATAXES(dset_in[dd]->daxes,dset_in[0]->daxes) ){
00059        fprintf(stderr,
00060                "++ THD_open_tcat: %s grid mismatch with %s\n",
00061                sar->str[0] , sar->str[dd] ) ;
00062      }
00063    }
00064    if( nerr > 0 ){
00065      for( dd=0 ; dd < ndset_in ; dd++ )
00066        if( dset_in[dd] != NULL ) DSET_delete(dset_in[dd]) ;
00067      free((void *)dset_in) ;
00068      NI_delete_str_array(sar) ;
00069      RETURN(NULL) ;
00070    }
00071 
00072    /*-- OK, start making new dataset --*/
00073 
00074    new_nvals = 0 ;
00075    for( dd=0 ; dd < ndset_in ; dd++ )
00076      new_nvals += DSET_NVALS(dset_in[dd]) ;
00077 
00078    for( dd=0 ; dd < ndset_in ; dd++ )
00079       if( DSET_TIMESTEP(dset_in[dd]) > 0.0 ) break ;  /* 1st 3D+time */
00080    if( dd == ndset_in ) dd = 0 ;
00081 
00082    dset_out = EDIT_empty_copy( dset_in[dd] ) ;
00083 
00084    EDIT_dset_items( dset_out ,
00085                       ADN_prefix    , "tcat" ,
00086                       ADN_func_type , ISANAT(dset_in[dd]) ? ANAT_EPI_TYPE
00087                                                           : FUNC_FIM_TYPE ,
00088                       ADN_ntt       , new_nvals ,
00089                       ADN_nvals     , new_nvals ,
00090                     ADN_none ) ;
00091    DSET_mallocize( dset_out ) ;
00092 
00093    /* check if we have a valid time axis; if not, make one up */
00094 
00095    if( DSET_TIMESTEP(dset_out) <= 0.0f ){
00096       float TR=1.0f , torg=0.0f , tdur=0.0f ;
00097       int tunits=UNITS_SEC_TYPE ;
00098       EDIT_dset_items( dset_out ,
00099                           ADN_tunits , tunits ,
00100                           ADN_ttdel  , TR ,
00101                           ADN_ttorg  , torg ,
00102                           ADN_ttdur  , tdur ,
00103                        ADN_none ) ;
00104    }
00105 
00106    dset_out->tcat_list = strdup( dlist ) ;
00107    dset_out->tcat_num  = ndset_in ;
00108    dset_out->tcat_len  = (int *)malloc(sizeof(int)*ndset_in) ;
00109    for( dd=0 ; dd < ndset_in ; dd++ ){
00110      dset_out->tcat_len[dd] = DSET_NVALS(dset_in[dd]) ;
00111      DSET_delete(dset_in[dd]) ;
00112    }
00113    free((void *)dset_in) ;
00114    NI_delete_str_array(sar) ;
00115 
00116 #if 0
00117 fprintf(stderr,"THD_open_tcat('%s'):",dset_out->tcat_list);
00118 for(dd=0;dd<ndset_in;dd++)fprintf(stderr," %d",dset_out->tcat_len[dd]);
00119 fprintf(stderr,"\n");
00120 #endif
00121 
00122    RETURN(dset_out) ;
00123 }

void THD_order_session THD_session   sess
 

Order the datasets within a session (anats first, funcs last). ---------------------------------------------------------------------------

Definition at line 622 of file thd_initsess.c.

References THD_session::dsset, ENTRY, ISANAT, ISFUNC, LAST_VIEW_TYPE, THD_session::num_dsset, and THD_MAX_SESSION_SIZE.

Referenced by THD_init_session().

00623 {
00624    THD_3dim_dataset *qset[THD_MAX_SESSION_SIZE][LAST_VIEW_TYPE+1] ;
00625    THD_3dim_dataset *dset ;
00626    int iview , ids , nds ;
00627 
00628 ENTRY("THD_order_session") ;
00629    if( sess == NULL || sess->num_dsset <= 1 ) EXRETURN ;
00630 
00631    /* put anats into qset */
00632 
00633    nds = 0 ;
00634    for( ids=0 ; ids < sess->num_dsset ; ids++ ){
00635      for( iview=0 ; iview <= LAST_VIEW_TYPE ; iview++ ){
00636        dset = sess->dsset[ids][iview] ;
00637        if( dset != NULL && ISANAT(dset) ) break ;
00638      }
00639      if( iview <= LAST_VIEW_TYPE ){
00640        for( iview=0 ; iview <= LAST_VIEW_TYPE ; iview++ )
00641          qset[nds][iview] = sess->dsset[ids][iview] ;
00642        nds++ ;
00643      }
00644    }
00645 
00646    /* put funcs into qset */
00647 
00648    for( ids=0 ; ids < sess->num_dsset ; ids++ ){
00649      for( iview=0 ; iview <= LAST_VIEW_TYPE ; iview++ ){
00650        dset = sess->dsset[ids][iview] ;
00651        if( dset != NULL && ISFUNC(dset) ) break ;
00652      }
00653      if( iview <= LAST_VIEW_TYPE ){
00654        for( iview=0 ; iview <= LAST_VIEW_TYPE ; iview++ )
00655          qset[nds][iview] = sess->dsset[ids][iview] ;
00656        nds++ ;
00657      }
00658    }
00659 
00660    /* copy qset back into sess, overwriting dsset */
00661 
00662    for( ids=0 ; ids < nds ; ids++ )
00663      for( iview=0 ; iview <= LAST_VIEW_TYPE ; iview++ )
00664        sess->dsset[ids][iview] = qset[ids][iview] ;
00665 
00666    sess->num_dsset = nds ;  /* shouldn't change */
00667    EXRETURN ;
00668 }

FD_brick* THD_oriented_brick THD_3dim_dataset  ,
char *   
 

Definition at line 97 of file thd_fdbrick.c.

References CURRENT_DAXES, ENTRY, ISVALID_DATAXES, ISVALID_DSET, OR3OK, ORCODE, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, RETURN, THD_3dim_dataset_to_brick(), THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by main(), r_new_resam_dset(), and RCREND_reload_dataset().

00098 {
00099    int r2l=0 , a2p=0 , i2s=0 , xx,yy,zz , pp=0,qq=0,rr=0 ;
00100    THD_dataxes *daxes ;
00101    FD_brick *br ;
00102 
00103 ENTRY("THD_oriented_brick") ;
00104 
00105    if( !ISVALID_DSET(dset) ||
00106        orients == NULL     ||
00107        strlen(orients) < 3   ) RETURN(NULL) ;
00108 
00109    daxes = CURRENT_DAXES(dset) ;
00110    if( !ISVALID_DATAXES(daxes) ) RETURN(NULL) ;
00111 
00112    xx = ORCODE( orients[0] ) ;
00113    yy = ORCODE( orients[1] ) ;
00114    zz = ORCODE( orients[2] ) ;
00115    if( !OR3OK(xx,yy,zz) ) RETURN(NULL) ;
00116 
00117    /*----- create FD_bricks for viewing purposes -----*/
00118 
00119    switch( daxes->xxorient ){
00120       case ORI_R2L_TYPE: r2l =  1 ; break ;
00121       case ORI_L2R_TYPE: r2l = -1 ; break ;
00122       case ORI_P2A_TYPE: a2p = -1 ; break ;
00123       case ORI_A2P_TYPE: a2p =  1 ; break ;
00124       case ORI_I2S_TYPE: i2s =  1 ; break ;
00125       case ORI_S2I_TYPE: i2s = -1 ; break ;
00126    }
00127 
00128    switch( daxes->yyorient ){
00129       case ORI_R2L_TYPE: r2l =  2 ; break ;
00130       case ORI_L2R_TYPE: r2l = -2 ; break ;
00131       case ORI_P2A_TYPE: a2p = -2 ; break ;
00132       case ORI_A2P_TYPE: a2p =  2 ; break ;
00133       case ORI_I2S_TYPE: i2s =  2 ; break ;
00134       case ORI_S2I_TYPE: i2s = -2 ; break ;
00135    }
00136 
00137    switch( daxes->zzorient ){
00138       case ORI_R2L_TYPE: r2l =  3 ; break ;
00139       case ORI_L2R_TYPE: r2l = -3 ; break ;
00140       case ORI_P2A_TYPE: a2p = -3 ; break ;
00141       case ORI_A2P_TYPE: a2p =  3 ; break ;
00142       case ORI_I2S_TYPE: i2s =  3 ; break ;
00143       case ORI_S2I_TYPE: i2s = -3 ; break ;
00144    }
00145 
00146    if( r2l==0 || a2p==0 || i2s==0 ) RETURN(NULL) ;
00147 
00148    switch( xx ){
00149       case ORI_R2L_TYPE: pp =  r2l ; break ;
00150       case ORI_L2R_TYPE: pp = -r2l ; break ;
00151       case ORI_P2A_TYPE: pp = -a2p ; break ;
00152       case ORI_A2P_TYPE: pp =  a2p ; break ;
00153       case ORI_I2S_TYPE: pp =  i2s ; break ;
00154       case ORI_S2I_TYPE: pp = -i2s ; break ;
00155    }
00156 
00157    switch( yy ){
00158       case ORI_R2L_TYPE: qq =  r2l ; break ;
00159       case ORI_L2R_TYPE: qq = -r2l ; break ;
00160       case ORI_P2A_TYPE: qq = -a2p ; break ;
00161       case ORI_A2P_TYPE: qq =  a2p ; break ;
00162       case ORI_I2S_TYPE: qq =  i2s ; break ;
00163       case ORI_S2I_TYPE: qq = -i2s ; break ;
00164    }
00165 
00166    switch( zz ){
00167       case ORI_R2L_TYPE: rr =  r2l ; break ;
00168       case ORI_L2R_TYPE: rr = -r2l ; break ;
00169       case ORI_P2A_TYPE: rr = -a2p ; break ;
00170       case ORI_A2P_TYPE: rr =  a2p ; break ;
00171       case ORI_I2S_TYPE: rr =  i2s ; break ;
00172       case ORI_S2I_TYPE: rr = -i2s ; break ;
00173    }
00174 
00175    if( pp==0 || qq==0 || rr==0 ) RETURN(NULL) ;
00176 
00177    br = THD_3dim_dataset_to_brick(dset,pp,qq,rr) ;
00178    RETURN(br) ;
00179 }

void THD_outlier_count THD_3dim_dataset  ,
float   ,
int **   ,
int *   
 

Definition at line 10 of file thd_outlier_count.c.

References calloc, DSET_load, DSET_LOADED, DSET_NUM_TIMES, DSET_NVOX, ENTRY, far, free, ISVALID_DSET, malloc, mri_free(), qginv(), qmed_float(), qmedmad_float(), THD_cliplevel(), THD_extract_array(), THD_median_brick(), and var.

Referenced by T3D_check_outliers().

00011 {
00012    int nvals , iv , nxyz , ii , oot , *ccc ;
00013    float alph,fmed,fmad , fbot,ftop ;
00014    MRI_IMAGE * flim ;
00015    float * far , * var , clip_val ;
00016 
00017 ENTRY("THD_outlier_count") ;
00018 
00019    /*-- sanity checks --*/
00020 
00021    if( !ISVALID_DSET(dset) ) EXRETURN ;
00022    if( qthr <= 0.0 || qthr >= 0.1 ) qthr = 0.001 ;
00023 
00024    nvals = DSET_NUM_TIMES(dset) ;
00025    nxyz  = DSET_NVOX(dset) ;
00026    if( nvals < 5 ){ *count = NULL ; *ctop = 0 ; EXRETURN ; }
00027    DSET_load(dset) ;
00028    if( !DSET_LOADED(dset) ){ *count = NULL ; *ctop = 0 ; EXRETURN ; }
00029 
00030    /*-- find clip level [will ignore voxels below this value] --*/
00031 
00032    flim = THD_median_brick( dset ) ;
00033    clip_val = THD_cliplevel( flim , 0.5 ) ;
00034    mri_free(flim) ;
00035 
00036    /*-- setup to count outliers --*/
00037 
00038    alph   = qginv(qthr/nvals) * sqrt(0.5*PI) ;
00039    *count = ccc = (int *) calloc( sizeof(int) , nvals ) ;
00040    var    = (float *) malloc( sizeof(float) * nvals ) ;
00041 
00042    /*--- loop over voxels and count ---*/
00043 
00044    far = (float *) calloc(sizeof(float),nvals+1) ;  /* 05 Nov 2001 */
00045 
00046    for( ii=0 ; ii < nxyz ; ii++ ){
00047 
00048       /*- get time series from voxel #ii -*/
00049 
00050       THD_extract_array( ii , dset , 0 , far ) ;          /* 05 Nov 2001 */
00051       memcpy(var,far,sizeof(float)*nvals ) ;              /* copy it */
00052 
00053       fmed = qmed_float( nvals , far ) ;                  /* median */
00054       if( clip_val > 0.0 && fmed < clip_val ) continue ;  /* below clip? */
00055       for( iv=0 ; iv < nvals ; iv++ )
00056          far[iv] = fabs(far[iv]-fmed) ;
00057       fmad = qmed_float( nvals , far ) ;                  /* MAD */
00058       fbot = fmed - alph*fmad ; ftop = fmed + alph*fmad ; /* inlier range */
00059 
00060       if( fmad > 0.0 ){                                   /* count outliers */
00061          for( iv=0 ; iv < nvals ; iv++ )
00062             if( var[iv] < fbot || var[iv] > ftop ) ccc[iv]++ ;
00063       }
00064 
00065    }
00066 
00067    free(far) ;  /* 05 Nov 2001 */
00068 
00069    for( iv=0 ; iv < nvals ; iv++ ) var[iv] = ccc[iv] ;    /* float-ize counts */
00070    qmedmad_float( nvals,var , &fmed,&fmad ) ; free(var) ; /* median and MAD */
00071    *ctop = (int)(fmed+3.5*fmad+0.499) ;                   /* too much? */
00072 
00073    EXRETURN ;
00074 }

float THD_pearson_corr int   ,
float *   ,
float *   
 

Definition at line 150 of file thd_correlate.c.

Referenced by main().

00151 {
00152    float xv=0 , yv=0 , xy=0 ;
00153    int ii ;
00154 
00155    for( ii=0 ; ii < n ; ii++ ){
00156       xv += x[ii]*x[ii] ; yv += y[ii]*y[ii] ; xy += x[ii]*y[ii] ;
00157    }
00158 
00159    if( xv <= 0.0 || yv <= 0.0 ) return 0.0 ;
00160    return xy/sqrt(xv*yv) ;
00161 }

int THD_peel_mask int    nx,
int    ny,
int    nz,
byte   mmm,
int    pdepth
 

Definition at line 817 of file thd_automask.c.

References mmm, nz, and top.

Referenced by mri_automask_image().

00818 {
00819    int nxy=nx*ny , ii,jj,kk , ijk , bot,top , pd=pdepth ;
00820    int nxp=nx-pd , nyp=ny-pd , nzp=nz-pd ;
00821    int num=0 , dnum , nite ;
00822 
00823    for( nite=0 ; nite < pd ; nite++ ){
00824     dnum = 0 ;
00825 
00826     for( kk=0 ; kk < nz ; kk++ ){
00827      for( jj=0 ; jj < ny ; jj++ ){
00828        ijk = jj*nx + kk*nxy ;
00829        for( bot=0 ; bot < nx && !mmm[bot+ijk]; bot++ ) ;
00830        top = bot+pd ; if( top >= nx ) continue ;
00831        for( ii=bot+1 ; ii <= top && mmm[ii+ijk] ; ii++ ) ;
00832        if( ii <= top ){ mmm[bot+ijk] = 0; dnum++; }
00833     }}
00834 
00835     for( kk=0 ; kk < nz ; kk++ ){
00836      for( jj=0 ; jj < ny ; jj++ ){
00837        ijk = jj*nx + kk*nxy ;
00838        for( top=nx-1 ; top >= 0 && !mmm[top+ijk]; top-- ) ;
00839        bot = top-pd ; if( bot < 0 ) continue ;
00840        for( ii=top-1 ; ii >= bot && mmm[ii+ijk] ; ii-- ) ;
00841        if( ii >= bot ){ mmm[top+ijk] = 0; dnum++; }
00842     }}
00843 
00844     for( kk=0 ; kk < nz ; kk++ ){
00845      for( ii=0 ; ii < nx ; ii++ ){
00846        ijk = ii + kk*nxy ;
00847        for( bot=0 ; bot < ny && !mmm[bot*nx+ijk] ; bot++ ) ;
00848        top = bot+pd ;
00849        if( top >= ny ) continue ;
00850        for( jj=bot+1 ; jj <= top && mmm[jj*nx+ijk] ; jj++ ) ;
00851        if( jj <= top ){ mmm[bot*nx+ijk] = 0; dnum++; }
00852     }}
00853 
00854     for( kk=0 ; kk < nz ; kk++ ){
00855      for( ii=0 ; ii < nx ; ii++ ){
00856        ijk = ii + kk*nxy ;
00857        for( top=ny-1 ; top >= 0 && !mmm[top*nx+ijk] ; top-- ) ;
00858        bot = top-pd ; if( bot < 0 ) continue ;
00859        for( jj=top-1 ; jj >= bot && mmm[jj*nx+ijk] ; jj-- ) ;
00860        if( jj >= bot ){ mmm[top*nx+ijk] = 0; dnum++; }
00861     }}
00862 
00863     for( jj=0 ; jj < ny ; jj++ ){
00864      for( ii=0 ; ii < nx ; ii++ ){
00865        ijk = ii + jj*nx ;
00866        for( top=nz-1 ; top >= 0 && !mmm[top*nxy+ijk] ; top-- ) ;
00867        bot = top-pd ; if( bot < 0 ) continue ;
00868        for( kk=top-1 ; kk >= bot && mmm[kk*nxy+ijk] ; kk-- ) ;
00869        if( kk >= bot ){ mmm[top*nxy+ijk] = 0; dnum++; }
00870     }}
00871 
00872     num += dnum ;
00873     if( dnum == 0 ) break ;
00874    }
00875 
00876    return num ;
00877 }

Boolean THD_purge_datablock THD_datablock  ,
int   
 

Definition at line 10 of file thd_purgedblk.c.

References THD_datablock::brick, DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DATABLOCK_MEM_SHARED, DBLK_ARRAY, DBLK_BRICK, DBLK_LOCKED, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_clear_data_pointer, THD_datablock::nvals, and THD_datablock::total_bytes.

Referenced by THD_delete_datablock(), THD_force_malloc_type(), THD_load_datablock(), and THD_write_datablock().

00011 {
00012    int ibr , nfreed ;
00013    void * ptr ;
00014 
00015    /*-- sanity checks --*/
00016 
00017    if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ) return False ;
00018    if( (blk->malloc_type & mem_type) == 0 )             return False ;
00019    if( DBLK_LOCKED(blk) )                               return False ;
00020 
00021    /*-- free the data space --*/
00022 
00023    nfreed = 0 ;
00024    switch( blk->malloc_type ){
00025 
00026       case DATABLOCK_MEM_MALLOC:
00027          for( ibr=0 ; ibr < blk->nvals ; ibr++ ){
00028             ptr = DBLK_ARRAY(blk,ibr) ;
00029             if( ptr != NULL ){ free(ptr) ; nfreed++ ; }
00030             mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00031          }
00032       return True ;
00033 
00034       case DATABLOCK_MEM_MMAP:
00035          ptr = DBLK_ARRAY(blk,0) ;
00036          if( ptr != NULL ){ munmap( ptr , (size_t)blk->total_bytes ) ; nfreed++ ; }
00037          for( ibr=0 ; ibr < blk->nvals ; ibr++ )
00038             mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00039       return True ;
00040 
00041       case DATABLOCK_MEM_SHARED:   /* can't be purged */
00042       return False ;
00043    }
00044 
00045    return False ;  /* shouldn't be reached */
00046 }

Boolean THD_purge_one_brick THD_datablock  ,
int   
 

Definition at line 52 of file thd_purgedblk.c.

References THD_datablock::brick, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_LOCKED, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_clear_data_pointer, and THD_datablock::nvals.

00053 {
00054    void * ptr ;
00055 
00056    /* sanity checks */
00057 
00058    if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ) return False ;
00059    if( DBLK_LOCKED(blk) )                               return False ;
00060    if( iv < 0 || iv >= blk->nvals )                     return False ;
00061    if( blk->malloc_type != DATABLOCK_MEM_MALLOC )       return False ;
00062 
00063    ptr = DBLK_ARRAY(blk,iv) ;
00064    if( ptr != NULL ) free(ptr) ;
00065    mri_clear_data_pointer( DBLK_BRICK(blk,iv) ) ;
00066    return True ;
00067 }

void THD_put_dset_row THD_3dim_dataset  ,
int   ,
int   ,
int   ,
int   ,
int   ,
void *    row
 

Definition at line 146 of file thd_dsetrow.c.

References DSET_ARRAY, DSET_BRICK_TYPE, DSET_NX, DSET_NY, DSET_NZ, ENTRY, nz, and THD_get_dset_rowcount().

Referenced by main(), THD_dataset_rowfillin(), and THD_dataset_zfillin().

00148 {
00149    void *brick ;
00150    int nrow , kind , nx,ny,nz,nxy , kbot,kdel,kk,ii ;
00151 
00152 ENTRY("THD_put_dset_row") ;
00153 
00154    nrow = THD_get_dset_rowcount( dset , dcode ) ;
00155    if( nrow < 1 ) EXRETURN ;
00156 
00157    nx = DSET_NX(dset) ;
00158    ny = DSET_NY(dset) ; nxy = nx*ny ;
00159    nz = DSET_NZ(dset) ;
00160 
00161    /*-- We will insert brick[kbot+i*kdel] for i=0..nrow-1 --*/
00162 
00163    switch( dcode ){
00164       case 1: case -1:
00165          if( yy < 0 || yy >= ny || zz < 0 || zz >= nz ) EXRETURN ;
00166          kbot = yy*nx + zz*nxy ; kdel = 1 ;
00167       break ;
00168 
00169       case 2: case -2:
00170          if( xx < 0 || xx >= nx || zz < 0 || zz >= nz ) EXRETURN ;
00171          kbot = xx + zz*nxy ; kdel = nx ;
00172       break ;
00173 
00174       case 3: case -3:
00175          if( xx < 0 || xx >= nx || yy < 0 || yy >= ny ) EXRETURN ;
00176          kbot = xx + yy*nx ; kdel = nxy ;
00177       break ;
00178    }
00179 
00180    kind  = DSET_BRICK_TYPE(dset,ival) ;
00181    brick = DSET_ARRAY(dset,ival) ;
00182 
00183    /*-- insert row, based on kind of data in sub-brick --*/
00184 
00185    switch( kind ){
00186 
00187       default: EXRETURN ;  /* bad */
00188 
00189       case MRI_short:{
00190          short *rr = (short *)row , *bb = (short *)brick ;
00191          if( dcode > 0 )
00192             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[ii] ;
00193          else
00194             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[nrow-1-ii] ;
00195       }
00196       break ;
00197 
00198       case MRI_byte:{
00199          byte *rr = (byte *)row , *bb = (byte *)brick ;
00200          if( dcode > 0 )
00201             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[ii] ;
00202          else
00203             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[nrow-1-ii] ;
00204       }
00205       break ;
00206 
00207       case MRI_complex:{
00208          complex *rr = (complex *)row , *bb = (complex *)brick ;
00209          if( dcode > 0 )
00210             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[ii] ;
00211          else
00212             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[nrow-1-ii] ;
00213       }
00214       break ;
00215 
00216       case MRI_float:{
00217          float *rr = (float *)row , *bb = (float *)brick ;
00218          if( dcode > 0 )
00219             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[ii] ;
00220          else
00221             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ) bb[kk+kbot] = rr[nrow-1-ii] ;
00222       }
00223       break ;
00224 
00225       case MRI_rgb:{
00226          byte *rr = (byte *)row , *bb = (byte *)brick ;
00227          if( dcode > 0 )
00228             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ){
00229                bb[3*(kk+kbot)  ] = rr[3*ii  ] ;
00230                bb[3*(kk+kbot)+1] = rr[3*ii+1] ;
00231                bb[3*(kk+kbot)+2] = rr[3*ii+2] ;
00232             }
00233          else
00234             for( ii=kk=0 ; ii < nrow ; ii++,kk+=kdel ){
00235                bb[3*(kk+kbot)  ] = rr[3*(nrow-1-ii)  ] ;
00236                bb[3*(kk+kbot)+1] = rr[3*(nrow-1-ii)+1] ;
00237                bb[3*(kk+kbot)+2] = rr[3*(nrow-1-ii)+2] ;
00238             }
00239       }
00240       break ;
00241    }
00242 
00243    EXRETURN ;
00244 }

float THD_pval_to_stat float    pval,
int    statcode,
float *    stataux
 

Definition at line 68 of file thd_statpval.c.

00069 {
00070    float stat = -1.0 ;   /* error flag */
00071 
00072    if( pval >= 0.999999 ) return 0.0 ;  /* WTF */
00073 
00074    if( stataux == NULL && statcode != FUNC_ZT_TYPE ) return pval ;
00075 
00076    switch( statcode ){  /* if statcode is illegal, will return -1 */
00077 
00078       /** the routines below are in mri_stats.c **/
00079 
00080       case FUNC_COR_TYPE:
00081          stat = correl_p2t( pval , stataux[0] , stataux[1] , stataux[2] ) ;
00082       break ;
00083 
00084       case FUNC_TT_TYPE:
00085          stat = student_p2t( pval , stataux[0] ) ;
00086       break ;
00087 
00088       case FUNC_FT_TYPE:
00089          stat = fstat_p2t( pval , stataux[0] , stataux[1] ) ;
00090       break ;
00091 
00092       case FUNC_ZT_TYPE:                /* only type that doesn't */
00093          stat = normal_p2t( pval ) ;    /* use stataux parameters */
00094       break ;
00095 
00096       case FUNC_CT_TYPE:
00097          stat = chisq_p2t( pval , stataux[0] ) ;
00098       break ;
00099 
00100       case FUNC_BT_TYPE:
00101          stat = beta_p2t( pval , stataux[0] , stataux[1] ) ;
00102       break ;
00103 
00104       case FUNC_BN_TYPE:
00105          stat = binomial_p2t( pval , stataux[0] , stataux[1] ) ;
00106       break ;
00107 
00108       case FUNC_GT_TYPE:
00109          stat = gamma_p2t( pval , stataux[0] , stataux[1] ) ;
00110       break ;
00111 
00112       case FUNC_PT_TYPE:
00113          stat = poisson_p2t( pval , stataux[0] ) ;
00114       break ;
00115    }
00116 
00117    return stat ;
00118 }

float THD_quadrant_corr int   ,
float *   ,
float *   
 

Definition at line 143 of file thd_correlate.c.

References quadrant_corr(), and quadrant_corr_prepare().

Referenced by main().

00144 {
00145    float xv = quadrant_corr_prepare(n,x) ;
00146    if( xv <= 0.0 ) return 0.0 ;
00147    return quadrant_corr( n,y,xv,x ) ;
00148 }

void THD_quadratic_detrend int   ,
float *   ,
float *   ,
float *   ,
float *   
 

Definition at line 111 of file thd_detrend.c.

References far, and get_quadratic_trend().

Referenced by main().

00113 {
00114    register int ii ;
00115    float f0 , f1 , f2 ;
00116 
00117    if( npt < 4 || far == NULL ) return ;
00118 
00119    get_quadratic_trend( npt , far , &f0 , &f1 , &f2 ) ;
00120 
00121    far[0] -= f0 ;
00122    for( ii=1 ; ii < npt ; ii++ ) far[ii] -= ( (f2*ii + f1)*ii + f0 ) ;
00123 
00124    if( xx0 != NULL ) *xx0 = f0 ;
00125    if( xx1 != NULL ) *xx1 = f1 ;
00126    if( xx2 != NULL ) *xx2 = f2 ;
00127 
00128    return ;
00129 }

void THD_read_all_atr char *    headername,
THD_datablock   blk
 

Given the rudiments of a datablock, read all the attributes into it -------------------------------------------------------------------------

Definition at line 24 of file thd_atr.c.

References ADDTO_KILL, THD_datablock::atr, ATR_ALLINC, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, ENTRY, FAIL, FIRST_ATR_TYPE, ATR_float::fl, ATR_int::in, ISVALID_DATABLOCK, THD_datablock::kl, LAST_ATR_TYPE, ATR_float::name, ATR_int::name, ATR_string::name, THD_datablock::natr, THD_datablock::natr_alloc, ATR_string::nch, ATR_float::nfl, ATR_int::nin, STRING_HAS_SUFFIX, strtod(), SUCCESS, THD_FATAL_ERROR, THD_MAX_NAME, THD_read_niml_atr(), THD_unzblock(), ATR_float::type, ATR_int::type, ATR_string::type, XtMalloc, and XtRealloc.

Referenced by THD_init_one_datablock().

00025 {
00026    ATR_any *next_atr ;
00027    int code , ii ;
00028    FILE *header_file ;
00029 
00030 ENTRY("THD_read_all_atr") ;
00031 
00032    if( ! ISVALID_DATABLOCK(blk) )
00033       THD_FATAL_ERROR( "Illegal datablock type in THD_read_all_atr" ) ;
00034 
00035    blk->natr       = 0 ;     /* initialize to no attributes */
00036    blk->natr_alloc = 0 ;
00037    blk->atr        = NULL ;
00038 
00039    /*--- certain types of filenames are verboten ---*/
00040 
00041    if( STRING_HAS_SUFFIX(headername,".mnc")    ) EXRETURN ;
00042    if( STRING_HAS_SUFFIX(headername,".nii")    ) EXRETURN ;
00043    if( STRING_HAS_SUFFIX(headername,".nii.gz") ) EXRETURN ;
00044    if( STRING_HAS_SUFFIX(headername,".mri")    ) EXRETURN ;
00045    if( STRING_HAS_SUFFIX(headername,".ctf")    ) EXRETURN ;
00046    if( STRING_HAS_SUFFIX(headername,".hdr")    ) EXRETURN ;
00047    if( STRING_HAS_SUFFIX(headername,".mpg")    ) EXRETURN ;
00048 
00049    /*--- open file; if unable to do so, exeunt ---*/
00050 
00051    header_file = fopen( headername , "r" ) ;
00052    if( header_file == NULL ) EXRETURN ;
00053 
00054    /*--- 01 Jun 2005: check if this is a NIML-style header file ---*/
00055 
00056    { char buf[1024] , *cpt ; int nbuf ;
00057      nbuf = fread( buf , 1 , 1023 , header_file ) ;    /* read first 1K */
00058      if( nbuf > 0 ){                                  /* got something? */
00059        buf[nbuf] = '\0' ;
00060        cpt = strstr( buf , "<AFNI_" ) ;
00061        if( cpt != NULL ){                        /*** NIML Dataset!!! ***/
00062          fclose( header_file ) ;                 /* is reopened by NIML */
00063          THD_read_niml_atr( headername , blk ) ; /** read the new way! **/
00064          EXRETURN ;
00065        }
00066      }
00067      rewind( header_file ) ; /*** old style dataset ==> read it below ***/
00068    }
00069 
00070    /*----- read attributes from the header file -----*/
00071 
00072    do{
00073       char aname[THD_MAX_NAME] , atypestr[THD_MAX_NAME] ;
00074       int  atype , acount ;
00075 
00076       atypestr[0] = aname[0] = '\0' ; acount = 0 ;
00077 
00078       code = fscanf( header_file ,
00079                      " type = %s name = %s count = %d" ,
00080                      atypestr , aname , &acount ) ;
00081 
00082       code = (code != 3 || acount < 1) ? FAIL : SUCCESS ;
00083       if( code == FAIL ) break ;  /* bad read */
00084 
00085       for( atype=FIRST_ATR_TYPE ; atype <= LAST_ATR_TYPE ; atype++ )
00086          if( strcmp(atypestr,ATR_typestr[atype]) == 0 ) break ;
00087 
00088       if( atype > LAST_ATR_TYPE ){ /* bad read */
00089          code = FAIL ;
00090          break ;
00091       }
00092 
00093       if( blk->natr == blk->natr_alloc ){  /* make new space */
00094          blk->natr_alloc  += ATR_ALLINC ;
00095          blk->atr          = (ATR_any *)
00096                              XtRealloc( (char *)blk->atr,
00097                                         sizeof(ATR_any) * blk->natr_alloc );
00098       }
00099       next_atr = &(blk->atr[blk->natr]) ;
00100       (blk->natr)++ ;
00101 
00102       switch( atype ){
00103 
00104          case ATR_FLOAT_TYPE:{
00105             ATR_float *new_atr = (ATR_float *) next_atr ;
00106             char bbb[256] ;
00107 
00108             new_atr->type = ATR_FLOAT_TYPE ;
00109             new_atr->name = XtNewString( aname ) ;
00110             new_atr->nfl  = acount ;
00111             new_atr->fl   = (float *) XtMalloc( sizeof(float) * acount ) ;
00112 
00113             code = 0 ;
00114             for( ii=0 ; ii < acount ; ii++ ){
00115 #if 0
00116                code += fscanf( header_file , "%f" , &(new_atr->fl[ii]) ) ;
00117 #else
00118                bbb[0] = '\0' ; fscanf( header_file , "%255s" , bbb ) ;
00119                if( bbb[0] != '\0' ){
00120                   new_atr->fl[ii] = strtod( bbb , NULL ) ;
00121                   code++ ;
00122                }
00123 #endif
00124             }
00125             code = (code != acount) ? FAIL : SUCCESS ;
00126 
00127             ADDTO_KILL( blk->kl , new_atr->name ) ;
00128             ADDTO_KILL( blk->kl , new_atr->fl ) ;
00129          }
00130          break ;
00131 
00132          case ATR_INT_TYPE:{
00133             ATR_int *new_atr = (ATR_int *) next_atr ;
00134 
00135             new_atr->type = ATR_INT_TYPE ;
00136             new_atr->name = XtNewString( aname ) ;
00137             new_atr->nin  = acount ;
00138             new_atr->in   = (int *) XtMalloc( sizeof(int) * acount ) ;
00139 
00140             code = 0 ;
00141             for( ii=0 ; ii < acount ; ii++ ){
00142                code += fscanf( header_file , "%d" , &(new_atr->in[ii]) ) ;
00143             }
00144             code = (code != acount) ? FAIL : SUCCESS ;
00145 
00146             ADDTO_KILL( blk->kl , new_atr->name ) ;
00147             ADDTO_KILL( blk->kl , new_atr->in ) ;
00148          }
00149          break ;
00150 
00151          case ATR_STRING_TYPE:{
00152             ATR_string *new_atr = (ATR_string *) next_atr ;
00153 
00154             new_atr->type = ATR_STRING_TYPE ;
00155             new_atr->name = XtNewString( aname ) ;
00156             new_atr->nch  = acount ;
00157             new_atr->ch   = (char *) XtMalloc( sizeof(char) * acount ) ;
00158 
00159             fscanf( header_file , " '" ) ;
00160 
00161             code = 0 ;
00162             for( ii=0 ; ii < acount ; ii++ ){
00163                code += fscanf( header_file , "%c" , &(new_atr->ch[ii]) ) ;
00164             }
00165             code = (code != acount) ? FAIL : SUCCESS ;
00166 
00167             THD_unzblock( acount , new_atr->ch ) ;
00168 
00169             ADDTO_KILL( blk->kl , new_atr->name ) ;
00170             ADDTO_KILL( blk->kl , new_atr->ch ) ;
00171          }
00172          break ;
00173       }  /* end of switch */
00174 
00175       if( code == FAIL ) break ;  /* exit if an error! */
00176    } while(1) ; /* end of for loop over all attributes */
00177 
00178    fclose( header_file ) ; EXRETURN ;
00179 }

THD_dvecmat THD_read_dvecmat char *   ,
int   
 

Definition at line 8 of file thd_read_vecmat.c.

References THD_3dim_dataset::dblk, DMAT_INV, DMATVEC, DSET_delete, ENTRY, ATR_float::fl, free, ISVALID_DSET, LOAD_DFVEC3, LOAD_DIAG_DMAT, LOAD_DMAT, THD_dvecmat::mm, NEGATE_DFVEC3, ATR_float::nfl, RETURN, THD_find_float_atr(), THD_open_one_dataset(), THD_rotcom_to_matvec(), and THD_dvecmat::vv.

Referenced by main().

00009 {
00010    THD_dvecmat dvm ;
00011    THD_dmat33 tmat ;
00012    THD_dfvec3 tvec ;
00013    FILE * fp ;
00014    double dd[12] ;
00015    int  nn ;
00016 
00017 ENTRY("THD_read_dvecmat") ;
00018 
00019    LOAD_DIAG_DMAT(tmat,0.0,0.0,0.0) ;  /* initialize to all 0s */
00020    LOAD_DFVEC3(tvec,0.0,0.0,0.0) ;
00021 
00022    if( fname == NULL || fname[0] == '\0' ){
00023       dvm.vv = tvec ; dvm.mm = tmat ; RETURN(dvm) ;
00024    }
00025 
00026    /*-- filename is "dataset::attribute" --*/
00027 
00028    if( strstr(fname,"::") != NULL ){  /*== read from dataset header ==*/
00029       char * dname = strdup(fname) ;
00030       char * cc = strstr(dname,"::") ;
00031       THD_3dim_dataset * dset ;
00032       ATR_float * atr ;
00033 
00034       *cc = '\0' ; cc += 2 ;  /* dname = dataset name ; cc = attribute name */
00035 
00036       dset = THD_open_one_dataset( dname ) ;
00037       if( !ISVALID_DSET(dset) ){
00038          fprintf(stderr,
00039                  "*** THD_read_dvecmat: can't open dataset %s\n",
00040                  dname) ;
00041          dvm.vv = tvec ; dvm.mm = tmat ; free(dname) ; RETURN(dvm) ;
00042       }
00043 
00044       atr = THD_find_float_atr( dset->dblk , cc ) ;
00045       if( atr == NULL ){
00046          fprintf(stderr,
00047                  "*** THD_read_dvecmat: can't find attribute %s in dataset %s\n",
00048                  cc,dname) ;
00049          dvm.vv = tvec ; dvm.mm = tmat ; free(dname) ; RETURN(dvm) ;
00050       }
00051 
00052       switch( atr->nfl ){
00053 
00054          default:
00055             fprintf(stderr,
00056                     "*** THD_read_dvecmat: can't read matrix+vector from dataset %s, attribute %s\n",
00057                     dname,cc) ;
00058             dvm.vv = tvec ; dvm.mm = tmat ; free(dname) ; RETURN(dvm) ;
00059          break ; /* unreachable */
00060 
00061          case 12: LOAD_DMAT(tmat,atr->fl[0],atr->fl[1],atr->fl[2],
00062                                  atr->fl[4],atr->fl[5],atr->fl[6],
00063                                  atr->fl[8],atr->fl[9],atr->fl[10] ) ;
00064                   LOAD_DFVEC3(tvec,atr->fl[3],atr->fl[7],atr->fl[11]) ;
00065          break ;
00066 
00067          case 9:  LOAD_DMAT(tmat,atr->fl[0],atr->fl[1],atr->fl[2],
00068                                  atr->fl[3],atr->fl[4],atr->fl[5],
00069                                  atr->fl[6],atr->fl[7],atr->fl[8] ) ;
00070                   LOAD_DFVEC3(tvec,0,0,0) ;
00071          break ;
00072       }
00073 
00074       free(dname) ; DSET_delete(dset) ;
00075 
00076    /*-- 14 Feb 2001: filename is "-rotate a b c -[ab]shift x y z" string --*/
00077 
00078    } else if( strstr(fname,"-rotate") != NULL ){  /*== compute directly ==*/
00079 
00080       dvm = THD_rotcom_to_matvec( NULL , fname ) ;  /* thd_rotangles.c */
00081       tvec = dvm.vv ; tmat = dvm.mm ;
00082 
00083    /*-- just a normal filename --*/
00084 
00085    } else {  /*== read numbers from file ==*/
00086 
00087       fp = fopen( fname , "r" ) ;
00088       if( fp == NULL ){
00089          fprintf(stderr,
00090                  "*** THD_read_dvecmat: can't open file %s\n",
00091                  fname) ;
00092          dvm.vv = tvec ; dvm.mm = tmat ; RETURN(dvm) ;
00093       }
00094 
00095       nn = fscanf(fp,"%lf %lf %lf %lf"      /* try to get 12 numbers */
00096                      "%lf %lf %lf %lf"
00097                      "%lf %lf %lf %lf" ,
00098                   dd+0,dd+1,dd+2 ,dd+3,
00099                   dd+4,dd+5,dd+6 ,dd+7,
00100                   dd+8,dd+9,dd+10,dd+11 ) ;
00101 
00102       switch( nn ){  /* how many did we actually read? */
00103 
00104          default:
00105             fprintf(stderr,
00106                     "*** THD_read_dvecmat: can't read matrix+vector from file %s\n",
00107                     fname) ;
00108             dvm.vv = tvec ; dvm.mm = tmat ; RETURN(dvm) ;
00109          break ; /* unreachable */
00110 
00111          case 12: LOAD_DMAT(tmat,dd[0],dd[1],dd[2],    /* 12 ==> matrix+vector */
00112                                  dd[4],dd[5],dd[6],
00113                                  dd[8],dd[9],dd[10] ) ;
00114                   LOAD_DFVEC3(tvec,dd[3],dd[7],dd[11]) ;
00115          break ;
00116 
00117          case 9:  LOAD_DMAT(tmat,dd[0],dd[1],dd[2],    /*  9 ==> matrix only */
00118                                  dd[3],dd[4],dd[5],
00119                                  dd[6],dd[7],dd[8] ) ;
00120                   LOAD_DFVEC3(tvec,0,0,0) ;
00121          break ;
00122       }
00123    }
00124 
00125    /*-- invert the transformation we just read?            --*/
00126    /*-- [y] = [R][x] + [v]       is transformation, so     --*/
00127    /*-- [x] = inv[R] - inv[R][v] is inverse transformation --*/
00128 
00129    if( invert ){
00130       THD_dmat33 imat ; THD_dfvec3 ivec ;
00131       imat = DMAT_INV(tmat) ;             /* matrix inverse */
00132       ivec = DMATVEC(imat,tvec) ;         /* multiply inverse into vector */
00133       tmat = imat ;
00134       tvec = ivec ; NEGATE_DFVEC3(tvec) ; /* negate vector */
00135    }
00136 
00137    /*-- store results and get outta here, dude! --*/
00138 
00139    dvm.vv = tvec ; dvm.mm = tmat ; RETURN(dvm) ;
00140 }

void THD_read_niml_atr char *    headername,
THD_datablock   blk
 

Read NIML-formatted attributes from the header file. [01 Jun 2005] -------------------------------------------------------------------------

Definition at line 185 of file thd_atr.c.

References ENTRY, MIN, NI_group::name, NI_BUFSIZE, NI_element_type(), NI_filesize(), NI_free_element(), NI_GROUP_TYPE, NI_read_element(), NI_stream_close(), NI_stream_open(), NI_stream_setbufsize(), STATUS, and THD_dblkatr_from_niml().

Referenced by THD_read_all_atr().

00186 {
00187    NI_stream ns ;
00188    void *nini ;
00189    NI_group *ngr ;
00190    char sname[2048] ;
00191    long fsize ;
00192 
00193 ENTRY("THD_read_niml_atr") ;
00194 
00195    /** open NIML stream to read from the file **/
00196 
00197    if( headername == NULL || *headername == '\0' || blk == NULL ) EXRETURN ;
00198    fsize = NI_filesize(headername) ; if( fsize <= 10 ) EXRETURN ;
00199    sprintf(sname,"file:%s",headername) ; STATUS(sname) ;
00200    ns = NI_stream_open( sname , "r" ) ;
00201    if( ns == (NI_stream)NULL ) EXRETURN ;
00202    if( fsize > NI_BUFSIZE ){
00203      fsize = MIN( 4*NI_BUFSIZE , fsize ) ;
00204      NI_stream_setbufsize( ns , fsize ) ;
00205    }
00206 
00207    /** read one group element from it (e.g., skipping the XML prolog) **/
00208 
00209    while(1){
00210      nini = NI_read_element( ns , 9 ) ;
00211      if( nini == NULL ){ NI_stream_close(ns); EXRETURN; }      /* bad! */
00212      if( NI_element_type(nini) == NI_GROUP_TYPE ) break ;      /* good */
00213      NI_free_element(nini) ;                       /* not what we want */
00214    }
00215    NI_stream_close( ns ) ;
00216    ngr = (NI_group *)nini ;
00217    if( strncmp(ngr->name,"AFNI_",5) != 0 ){ NI_free_element(ngr); EXRETURN; }
00218 
00219    /** actually process element, then exit stage right **/
00220 
00221    THD_dblkatr_from_niml( ngr , blk ) ;  /* cf. thd_nimlatr.c */
00222    NI_free_element( ngr ) ;
00223    EXRETURN ;
00224 }

void THD_reconcile_parents THD_sessionlist  
 

Definition at line 35 of file thd_reconpar.c.

References THD_3dim_dataset::anat_parent, THD_3dim_dataset::anat_parent_idcode, THD_3dim_dataset::anat_parent_name, THD_slist_find::dset, THD_session::dsset, ENTRY, FIND_IDCODE, FIND_NAME, FIRST_VIEW_TYPE, IFNOANAT, IFNOWARP, ISVALID_SESSIONLIST, ISZERO_IDCODE, LAST_VIEW_TYPE, THD_session::num_dsset, THD_sessionlist::num_sess, SHOW_PARENTING, THD_sessionlist::ssar, THD_dset_in_sessionlist(), THD_3dim_dataset::warp_parent, THD_3dim_dataset::warp_parent_idcode, and THD_3dim_dataset::warp_parent_name.

Referenced by AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_rescan_session_NEW(), and AFNI_rescan_session_OLD().

00036 {
00037    int iss , idd , ivv , jss , imm , needed ;
00038    THD_session      * sess ;
00039    THD_3dim_dataset * dset_orph ;
00040    THD_slist_find   find ;
00041 
00042 ENTRY("THD_reconcile_parents") ;
00043 
00044    /*-- sanity check --*/
00045 
00046    if( ! ISVALID_SESSIONLIST(ssl) || ssl->num_sess <= 0 ) EXRETURN ;
00047 
00048    /*-- for each session in the list --*/
00049 
00050    for( iss=0 ; iss < ssl->num_sess ; iss++ ){
00051       sess = ssl->ssar[iss] ;
00052 
00053       /*-- for each dataset in the session --*/
00054 
00055       for( idd=0 ; idd < sess->num_dsset ; idd++ ){
00056          for( ivv=FIRST_VIEW_TYPE ; ivv <= LAST_VIEW_TYPE ; ivv++ ){
00057 
00058           dset_orph = sess->dsset[idd][ivv] ;
00059           if( dset_orph == NULL ) continue ;
00060 
00061             /*-- if it needs an anatomy parent --*/
00062 
00063           if( dset_orph->anat_parent == NULL ){  /* 28 Dec 2002 */
00064             needed = 0 ;
00065             if( ! ISZERO_IDCODE(dset_orph->anat_parent_idcode) ){
00066                needed = 1 ;
00067                find = THD_dset_in_sessionlist( FIND_IDCODE ,
00068                                                &(dset_orph->anat_parent_idcode),
00069                                                ssl , iss ) ;
00070                dset_orph->anat_parent = find.dset ;
00071                if( dset_orph->anat_parent != NULL )
00072                   SHOW_PARENTING("(ID) anat_parent",dset_orph,dset_orph->anat_parent) ;
00073             }
00074             if( dset_orph->anat_parent == NULL && strlen(dset_orph->anat_parent_name) > 0 ){
00075                needed = 1 ;
00076                find = THD_dset_in_sessionlist( FIND_NAME ,
00077                                                dset_orph->anat_parent_name,
00078                                                ssl , iss ) ;
00079                dset_orph->anat_parent = find.dset ;
00080                if( dset_orph->anat_parent != NULL )
00081                   SHOW_PARENTING("(NAME) anat_parent",dset_orph,dset_orph->anat_parent) ;
00082             }
00083             IFNOANAT(dset_orph) ;
00084           }
00085 
00086             /*-- if it needs a warp parent --*/
00087 
00088           if( dset_orph->warp_parent == NULL ){  /* 28 Dec 2002 */
00089             needed = 0 ;
00090             if( ! ISZERO_IDCODE(dset_orph->warp_parent_idcode) ){
00091                needed = 1 ;
00092                find = THD_dset_in_sessionlist( FIND_IDCODE ,
00093                                                &(dset_orph->warp_parent_idcode),
00094                                                ssl , iss ) ;
00095                dset_orph->warp_parent = find.dset ;
00096                if( dset_orph->warp_parent != NULL )
00097                   SHOW_PARENTING("(ID) warp_parent",dset_orph,dset_orph->warp_parent) ;
00098             }
00099             if( dset_orph->warp_parent == NULL && strlen(dset_orph->warp_parent_name) > 0 ){
00100                needed = 1 ;
00101                find = THD_dset_in_sessionlist( FIND_NAME ,
00102                                                dset_orph->warp_parent_name,
00103                                                ssl , iss ) ;
00104                dset_orph->warp_parent = find.dset ;
00105                if( dset_orph->warp_parent != NULL )
00106                   SHOW_PARENTING("(NAME) warp_parent",dset_orph,dset_orph->warp_parent) ;
00107             }
00108             IFNOWARP(dset_orph) ;
00109           }
00110 
00111          }
00112       }  /* end of loop over anat datasets */
00113 
00114    }  /* end of loop over sessions */
00115 
00116    EXRETURN ;
00117 }

MRI_IMAGE* THD_rms_brick THD_3dim_dataset   dset
 

Compute RMS brick of a dataset. [15 Apr 2005 - RWCox] -------------------------------------------------------------------

Definition at line 86 of file thd_median.c.

References calloc, DSET_BRICK, DSET_BRICK_FACTOR, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, ENTRY, free, ISVALID_DSET, MRI_FLOAT_PTR, mri_new_conforming, mri_scale_to_float(), RETURN, and THD_extract_array().

Referenced by read_input_data().

00087 {
00088    int nvox , nvals , ii , jj ;
00089    MRI_IMAGE *tsim , *medim ;
00090    float *medar , sum,fac ;
00091    float *tsar ;
00092 
00093 ENTRY("THD_rms_brick") ;
00094 
00095    if( !ISVALID_DSET(dset) ) RETURN(NULL) ;
00096    DSET_load(dset) ;
00097    if( !DSET_LOADED(dset) ) RETURN(NULL) ;
00098 
00099    nvals = DSET_NVALS(dset)   ; fac = 1.0 / nvals ;
00100    tsim  = DSET_BRICK(dset,0) ;
00101 
00102    if( nvals == 1 ){
00103      medim = mri_scale_to_float( DSET_BRICK_FACTOR(dset,0), tsim ) ;
00104      RETURN(medim) ;
00105    }
00106 
00107    medim = mri_new_conforming( tsim , MRI_float ) ;
00108    medar = MRI_FLOAT_PTR(medim) ;
00109    nvox  = DSET_NVOX(dset) ;
00110 
00111    tsar = (float *) calloc( sizeof(float),nvals+1 ) ;
00112    for( ii=0 ; ii < nvox ; ii++ ){
00113       THD_extract_array( ii , dset , 0 , tsar ) ;
00114       for( sum=0.0,jj=0 ; jj < nvals ; jj++ ) sum += tsar[jj]*tsar[jj] ;
00115       medar[ii] = sqrt(fac * sum) ;
00116    }
00117 
00118    free(tsar) ; RETURN(medim) ;
00119 }

MRI_IMAGE* THD_rota3D MRI_IMAGE  ,
int   ,
float   ,
int   ,
float   ,
int   ,
float   ,
int   ,
float   ,
float   ,
float   
 

Definition at line 468 of file thd_rot3d.c.

References MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, EDIT_coerce_type(), MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FLOAT_PTR, MRI_IS_3D, mri_new_vol(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, and THD_rota_vol().

Referenced by mri_3dalign_one(), and mri_3dalign_setup().

00471 {
00472    MRI_IMAGE * jm ;
00473    float * jvol ;
00474 
00475    if( ! MRI_IS_3D(im) ){
00476       fprintf(stderr,"\n*** THD_rota3D: non-3D image input!\n") ;
00477       return NULL ;
00478    }
00479 
00480    jm = mri_new_vol( im->nx , im->ny , im->nz , MRI_float ) ;
00481    MRI_COPY_AUX(jm,im) ;
00482    jvol = MRI_FLOAT_PTR(jm) ;
00483 
00484    EDIT_coerce_type( im->nvox ,
00485                      im->kind , mri_data_pointer(im) , MRI_float , jvol ) ;
00486 
00487    THD_rota_vol(      im->nx ,       im->ny ,       im->nz  ,
00488                  fabs(im->dx) , fabs(im->dy) , fabs(im->dz) , jvol ,
00489                  ax1,th1 , ax2,th2 , ax3,th3 , dcode , dx,dy,dz ) ;
00490 
00491    return jm ;
00492 }

MRI_IMAGE* THD_rota3D_matvec MRI_IMAGE  ,
THD_dmat33   ,
THD_dfvec3   
 

Definition at line 586 of file thd_rot3d.c.

References MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, EDIT_coerce_type(), MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FLOAT_PTR, MRI_IS_3D, mri_new_vol(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, and THD_rota_vol_matvec().

00587 {
00588    MRI_IMAGE * jm ;
00589    float * jvol ;
00590 
00591    if( ! MRI_IS_3D(im) ){
00592       fprintf(stderr,"\n*** THD_rota3D_matvec: non-3D image input!\n") ;
00593       return NULL ;
00594    }
00595 
00596    jm = mri_new_vol( im->nx , im->ny , im->nz , MRI_float ) ;
00597    MRI_COPY_AUX(jm,im) ;
00598    jvol = MRI_FLOAT_PTR(jm) ;
00599 
00600    EDIT_coerce_type( im->nvox ,
00601                      im->kind , mri_data_pointer(im) , MRI_float , jvol ) ;
00602 
00603    THD_rota_vol_matvec(      im->nx ,       im->ny ,       im->nz  ,
00604                        fabs(im->dx) , fabs(im->dy) , fabs(im->dz) , jvol ,
00605                        rmat , tvec ) ;
00606    return jm ;
00607 }

void THD_rota_byte_mode int   
 

Definition at line 27 of file thd_rot3d_byte.c.

References icode, MRI_NN, MRI_TSSHIFT, NNBOT, sbot, and TSBOT.

00028 {
00029    if( code == MRI_NN ){
00030       icode = MRI_NN      ; sbot = NNBOT ;
00031    } else {
00032       icode = MRI_TSSHIFT ; sbot = TSBOT ;
00033    }
00034 }

void THD_rota_clearpad void   
 

Definition at line 349 of file thd_rot3d.c.

References rotpset, rotpx, rotpy, and rotpz.

00350 {
00351    rotpx=rotpy=rotpz=0; rotpset=1; return;
00352 }

void THD_rota_method int   
 

Definition at line 26 of file thd_rot3d.c.

References MRI_CUBIC, MRI_FOURIER, MRI_FOURIER_NOPAD, MRI_HEPTIC, MRI_LINEAR, MRI_NN, MRI_QUINTIC, MRI_TSSHIFT, shift_method, and shifter.

Referenced by main(), mri_3dalign_one(), mri_3dalign_setup(), and NUD_rotate().

00027 {
00028    shift_method = mode ;
00029    switch( mode ){
00030       case MRI_NN:      shifter = nn_shift2    ; break ;
00031       case MRI_TSSHIFT: shifter = ts_shift2    ; break ;  /* Dec 1999 */
00032 
00033       case MRI_LINEAR:  shifter = lin_shift2   ; break ;
00034       case MRI_FOURIER: shifter = fft_shift2   ; break ;
00035       default:
00036       case MRI_CUBIC:   shifter = cub_shift2   ; break ;
00037       case MRI_QUINTIC: shifter = quint_shift2 ; break ;  /* Nov 1998 */
00038       case MRI_HEPTIC:  shifter = hept_shift2  ; break ;  /* Nov 1998 */
00039 
00040       case MRI_FOURIER_NOPAD: shifter = fft_shift2   ; break ;  /* 13 May 2003 */
00041    }
00042    return ;
00043 }

void THD_rota_setpad int   ,
int   ,
int   
 

Definition at line 338 of file thd_rot3d.c.

References rotpset, rotpx, rotpy, and rotpz.

Referenced by main(), THD_rota_envpad(), and VL_command_line().

00339 {
00340    rotpx = (px > 0) ? px : 0 ;
00341    rotpy = (py > 0) ? py : 0 ;
00342    rotpz = (pz > 0) ? pz : 0 ;
00343    rotpset = 1 ;               /* 05 Feb 2001 */
00344    return ;
00345 }

void THD_rota_vol int   ,
int   ,
int   ,
float   ,
float   ,
float   ,
float *   ,
int   ,
float   ,
int   ,
float   ,
int   ,
float   ,
int   ,
float   ,
float   ,
float   
 

Definition at line 374 of file thd_rot3d.c.

References apply_3shear(), DUMP_3SHEAR, EDIT_volpad_even, ENTRY, free, ISVALID_3SHEAR, nz, rot_to_shear(), rotpx, rotpy, rotpz, THD_rota_envpad(), and top.

Referenced by NUD_rotate(), and THD_rota3D().

00378 {
00379    MCW_3shear shr ;
00380 
00381 #ifdef CLIPIT
00382    register float bot , top ;
00383    register int   nxyz=nx*ny*nz , ii ;
00384 #endif
00385 
00386 ENTRY("THD_rota_vol") ;
00387 
00388    if( nx < 2 || ny < 2 || nz < 2 || vol == NULL ) EXRETURN ;
00389 
00390    if( xdel == 0.0 ) xdel = 1.0 ;
00391    if( ydel == 0.0 ) ydel = 1.0 ;
00392    if( zdel == 0.0 ) zdel = 1.0 ;
00393 
00394    if( th1 == 0.0 && th2 == 0.0 && th3 == 0.0 ){  /* nudge rotation */
00395       th1 = 1.e-6 ; th2 = 1.1e-6 ; th3 = 0.9e-6 ;
00396    }
00397 
00398 #if 0
00399 fprintf(stderr,"THD_rota_vol:\n") ;
00400 fprintf(stderr,"  th1=%g  th2=%g  th3=%g\n",th1,th2,th3) ;
00401 fprintf(stderr,"  dx=%g  dy=%g  dz=%g\n",dx,dy,dz) ;
00402 fprintf(stderr,"  xdel=%g  ydel=%g  zdel=%g\n",xdel,ydel,zdel) ;
00403 #endif
00404 
00405    shr = rot_to_shear( ax1,-th1 , ax2,-th2 , ax3,-th3 ,
00406                        dcode,dx,dy,dz , xdel,ydel,zdel ) ;
00407 
00408    if( ! ISVALID_3SHEAR(shr) ){
00409       fprintf(stderr,"*** THD_rota_vol: can't compute shear transformation!\n") ;
00410       EXRETURN ;
00411    }
00412 
00413 #if 0
00414    if( MRILIB_verbose )
00415      DUMP_3SHEAR("Computed shear",shr) ;
00416 #endif
00417 
00418 #ifdef CLIPIT
00419    bot = top = vol[0] ;
00420    for( ii=1 ; ii < nxyz ; ii++ ){
00421            if( vol[ii] < bot ) bot = vol[ii] ;
00422       else if( vol[ii] > top ) top = vol[ii] ;
00423    }
00424    if( bot >= top ) EXRETURN ;
00425 #endif
00426 
00427    /********************************/
00428    /* 02 Feb 2001: include padding */
00429 
00430    { float * vvv , *www ;
00431      int nxp , nyp , nzp ;
00432 
00433      THD_rota_envpad() ;  /* 05 Feb 2001 */
00434 
00435      nxp=nx+2*rotpx ; nyp=ny+2*rotpy ; nzp=nz+2*rotpz ;
00436 
00437      if( rotpx > 0 && rotpy > 0 && rotpz > 0 )
00438         vvv = EDIT_volpad_even( rotpx,rotpy,rotpz , nx,ny,nz , MRI_float,vol ) ;
00439      else
00440         vvv = vol ;
00441 
00442      apply_3shear( shr , nxp,nyp,nzp , vvv ) ;  /*-- do the actual rotation! --*/
00443 
00444      if( vvv != vol ){
00445         www = EDIT_volpad_even( -rotpx,-rotpy,-rotpz , nxp,nyp,nzp , MRI_float,vvv ) ;
00446         free(vvv) ;
00447         memcpy( vol , www , sizeof(float)*nx*ny*nz ) ; free(www) ;
00448      }
00449    }
00450 
00451    /********************************/
00452 
00453 #ifdef CLIPIT
00454    for( ii=0 ; ii < nxyz ; ii++ ){
00455            if( vol[ii] < bot ) vol[ii] = bot ;
00456       else if( vol[ii] > top ) vol[ii] = top ;
00457    }
00458 #endif
00459 
00460    EXRETURN ;
00461 }

void THD_rota_vol_byte int   ,
int   ,
int   ,
float   ,
float   ,
float   ,
byte  ,
int   ,
float   ,
int   ,
float   ,
int   ,
float   ,
int   ,
float   ,
float   ,
float   ,
Tmask  
 

void THD_rota_vol_matvec int   ,
int   ,
int   ,
float   ,
float   ,
float   ,
float *   ,
THD_dmat33   ,
THD_dfvec3   
 

Definition at line 505 of file thd_rot3d.c.

References apply_3shear(), DUMP_3SHEAR, EDIT_volpad_even, free, ISVALID_3SHEAR, nz, rot_to_shear_matvec(), rotpx, rotpy, rotpz, THD_rota_envpad(), and top.

Referenced by main(), and THD_rota3D_matvec().

00508 {
00509    MCW_3shear shr ;
00510    int dcode ;
00511 
00512 #ifdef CLIPIT
00513    register float bot , top ;
00514    register int   nxyz=nx*ny*nz , ii ;
00515 #endif
00516 
00517    if( nx < 2 || ny < 2 || nz < 2 || vol == NULL ) return ;
00518 
00519    if( xdel == 0.0 ) xdel = 1.0 ;
00520    if( ydel == 0.0 ) ydel = 1.0 ;
00521    if( zdel == 0.0 ) zdel = 1.0 ;
00522 
00523    shr = rot_to_shear_matvec( rmat , tvec , xdel,ydel,zdel ) ;
00524 
00525    if( ! ISVALID_3SHEAR(shr) ){
00526       fprintf(stderr,"*** THD_rota_vol: can't compute shear transformation!\n") ;
00527       return ;
00528    }
00529 
00530 #if 0
00531    if( MRILIB_verbose )
00532      DUMP_3SHEAR("Computed shear",shr) ;
00533 #endif
00534 
00535 #ifdef CLIPIT
00536    bot = top = vol[0] ;
00537    for( ii=1 ; ii < nxyz ; ii++ ){
00538            if( vol[ii] < bot ) bot = vol[ii] ;
00539       else if( vol[ii] > top ) top = vol[ii] ;
00540    }
00541    if( bot >= top ) return ;
00542 #endif
00543 
00544    /********************************/
00545    /* 02 Feb 2001: include padding */
00546 
00547    { float * vvv , *www ;
00548      int nxp , nyp , nzp ;
00549 
00550      THD_rota_envpad() ;  /* 05 Feb 2001 */
00551 
00552      nxp=nx+2*rotpx ; nyp=ny+2*rotpy ; nzp=nz+2*rotpz ;
00553 
00554      if( rotpx > 0 && rotpy > 0 && rotpz > 0 )
00555         vvv = EDIT_volpad_even( rotpx,rotpy,rotpz , nx,ny,nz , MRI_float,vol ) ;
00556      else
00557         vvv = vol ;
00558 
00559      apply_3shear( shr , nxp,nyp,nzp , vvv ) ;  /*-- do the actual rotation! --*/
00560 
00561      if( vvv != vol ){
00562         www = EDIT_volpad_even( -rotpx,-rotpy,-rotpz , nxp,nyp,nzp , MRI_float,vvv ) ;
00563         free(vvv) ;
00564         memcpy( vol , www , sizeof(float)*nx*ny*nz ) ; free(www) ;
00565      }
00566    }
00567 
00568    /********************************/
00569 
00570 #ifdef CLIPIT
00571    for( ii=0 ; ii < nxyz ; ii++ ){
00572            if( vol[ii] < bot ) vol[ii] = bot ;
00573       else if( vol[ii] > top ) vol[ii] = top ;
00574    }
00575 #endif
00576 
00577    return ;
00578 }

void THD_rota_vol_matvec_byte int   ,
int   ,
int   ,
float   ,
float   ,
float   ,
byte  ,
THD_mat33   ,
THD_fvec3   ,
Tmask  
 

void THD_rotangle_user_to_dset THD_3dim_dataset  ,
float   ,
char   ,
float   ,
char   ,
float   ,
char   ,
float *   ,
int *   ,
float *   ,
int *   ,
float *   ,
int *   
 

Definition at line 32 of file thd_rotangles.c.

References ENTRY, mangle_angle(), and THD_handedness().

Referenced by main(), and THD_rotcom_to_matvec().

00039 {
00040 ENTRY("THD_rotangle_user_to_dset") ;
00041 
00042    mangle_angle( dset, th1_in, ax1_code, th1_out, ax1_out ) ;
00043    mangle_angle( dset, th2_in, ax2_code, th2_out, ax2_out ) ;
00044    mangle_angle( dset, th3_in, ax3_code, th3_out, ax3_out ) ;
00045 
00046    if( THD_handedness(dset) < 0 ){
00047       *th1_out = -(*th1_out) ;
00048       *th2_out = -(*th2_out) ;
00049       *th3_out = -(*th3_out) ;
00050    }
00051 
00052    EXRETURN ;
00053 }

THD_dvecmat THD_rotcom_to_matvec THD_3dim_dataset  ,
char *   
 

Definition at line 179 of file thd_rotangles.c.

References DMATVEC, ENTRY, LOAD_DFVEC3, LOAD_DIAG_DMAT, THD_dvecmat::mm, RETURN, rot_to_matrix(), THD_axcode(), THD_rotangle_user_to_dset(), and THD_dvecmat::vv.

Referenced by main(), and THD_read_dvecmat().

00180 {
00181    THD_dvecmat out ;
00182    int nn , rpos=0 , nrc ;
00183    char *buf ;
00184 
00185 ENTRY("THD_rotcom_to_matvec") ;
00186 
00187    LOAD_DIAG_DMAT(out.mm,1,1,1) ;  /* identity matrix */
00188    LOAD_DFVEC3(out.vv,0,0,0) ;     /* and zero shift */
00189 
00190    if( rotcom == NULL || rotcom[0] == '\0' ) RETURN(out) ;
00191 
00192    /*-- compute rotation matrix --*/
00193 
00194    nrc = strlen(rotcom) ;
00195    buf = strstr(rotcom,"-rotate") ;
00196    if( buf != NULL && (buf-rotcom)+10 < nrc ){
00197       float th1,th2,th3 , dh1,dh2,dh3 ;
00198       char  cp1,cp2,cp3 ;
00199       int   ax1,ax2,ax3 ;
00200 
00201       nn = sscanf( buf+7, "%f%c %f%c %f%c",
00202                    &th1,&cp1, &th2,&cp2, &th3,&cp3 );
00203       if( nn < 6 ) RETURN(out) ;
00204       if( isspace(cp1) ) cp1 = 'x' ;  /* should not happen */
00205       if( isspace(cp2) ) cp2 = 'y' ;
00206       if( isspace(cp3) ) cp3 = 'z' ;
00207 
00208       THD_rotangle_user_to_dset( dset , th1,cp1 , th2,cp2 , th3,cp3 ,
00209                                  &dh1,&ax1 , &dh2,&ax2 , &dh3,&ax3   ) ;
00210 
00211       out.mm = rot_to_matrix( ax1 , -(PI/180.0)*dh1,
00212                               ax2 , -(PI/180.0)*dh2,
00213                               ax3 , -(PI/180.0)*dh3 ) ;
00214    }
00215 
00216    /*-- compute shift --*/
00217 
00218                      buf = strstr(rotcom,"-ashift") ;
00219    if( buf == NULL ) buf = strstr(rotcom,"-bshift") ;
00220 
00221    if( buf != NULL && (buf-rotcom)+10 < nrc ){
00222       int bs = (buf[1] == 'b') ;  /* save the BS for later */
00223       float dx,dy,dz , qdx=0,qdy=0,qdz=0 ;
00224       char  cdx,cdy,cdz ;
00225       int   adx,ady,adz ;
00226 
00227       nn = sscanf( buf+7, "%f%c %f%c %f%c",
00228                    &dx,&cdx, &dy,&cdy, &dz,&cdz );
00229       if( nn < 6 ) RETURN(out) ;
00230 
00231       adx = THD_axcode(dset,cdx) ;
00232       if( adx > -99 || dx != 0.0 ){
00233          switch( adx ){
00234             case  1: qdx = -dx ; break ;
00235             default:
00236             case -1: qdx =  dx ; break ;
00237             case  2: qdy = -dx ; break ;
00238             case -2: qdy =  dx ; break ;
00239             case  3: qdz = -dx ; break ;
00240             case -3: qdz =  dx ; break ;
00241          }
00242       }
00243 
00244       ady = THD_axcode(dset,cdy) ;
00245       if( ady > -99 || dy != 0.0 ){
00246          switch( ady ){
00247             case  1: qdx = -dy ; break ;
00248             case -1: qdx =  dy ; break ;
00249             case  2: qdy = -dy ; break ;
00250             default:
00251             case -2: qdy =  dy ; break ;
00252             case  3: qdz = -dy ; break ;
00253             case -3: qdz =  dy ; break ;
00254          }
00255       }
00256 
00257       adz = THD_axcode(dset,cdz) ;
00258       if( adz > -99 || dz != 0.0 ){
00259          switch( adz ){
00260             case  1: qdx = -dz ; break ;
00261             case -1: qdx =  dz ; break ;
00262             case  2: qdy = -dz ; break ;
00263             case -2: qdy =  dz ; break ;
00264             case  3: qdz = -dz ; break ;
00265             default:
00266             case -3: qdz =  dz ; break ;
00267          }
00268       }
00269 
00270       LOAD_DFVEC3( out.vv , qdx,qdy,qdz ) ;
00271       if( bs ){
00272          THD_dfvec3 qv = DMATVEC( out.mm , out.vv ) ;
00273          out.vv = qv ;
00274       }
00275    }
00276 
00277    RETURN(out) ;
00278 }

void THD_set_atr THD_datablock  ,
char *   ,
int   ,
int   ,
void *   
 

Definition at line 406 of file thd_atr.c.

References ADDTO_KILL, THD_datablock::atr, ATR_ALLINC, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, ENTRY, ATR_float::fl, ATR_int::in, ISVALID_DATABLOCK, THD_datablock::kl, ATR_float::name, ATR_int::name, ATR_string::name, THD_datablock::natr, THD_datablock::natr_alloc, ATR_string::nch, ATR_float::nfl, ATR_int::nin, SINGLE_KILL, STATUS, THD_FATAL_ERROR, THD_find_atr(), ATR_any::type, ATR_float::type, ATR_int::type, ATR_string::type, XtMalloc, and XtRealloc.

Referenced by main(), THD_insert_atr(), THD_set_char_atr(), THD_set_float_atr(), and THD_set_int_atr().

00408 {
00409    ATR_any *old_atr , *atr ;
00410 
00411 ENTRY("THD_set_atr") ;
00412 
00413    if( ! ISVALID_DATABLOCK(blk) )
00414      THD_FATAL_ERROR( "Illegal block type in THD_set_atr" ) ;
00415 
00416    if( acount < 0 || ar == NULL || aname == NULL )
00417      THD_FATAL_ERROR( "Illegal input data in THD_set_atr" ) ;
00418 
00419    old_atr = THD_find_atr( blk , aname ) ;  /* find matching name */
00420 
00421    if( old_atr != NULL ){  /* if an attribute with this name already is */
00422 
00423       atr = old_atr ;
00424 
00425       switch( old_atr->type ){  /* free data in old attribute */
00426 
00427          default: break ;  /* something unpleasant */
00428 
00429          case ATR_FLOAT_TYPE:{
00430             ATR_float *aa = (ATR_float *) old_atr ;
00431 
00432             SINGLE_KILL( blk->kl , aa->name ) ;
00433             SINGLE_KILL( blk->kl , aa->fl   ) ;
00434          }
00435          break ;
00436 
00437          case ATR_INT_TYPE:{
00438             ATR_int *aa = (ATR_int *) old_atr ;
00439 
00440             SINGLE_KILL( blk->kl , aa->name ) ;
00441             SINGLE_KILL( blk->kl , aa->in   ) ;
00442          }
00443          break ;
00444 
00445          case ATR_STRING_TYPE:{
00446             ATR_string *aa = (ATR_string *) old_atr ;
00447 
00448             SINGLE_KILL( blk->kl , aa->name ) ;
00449             SINGLE_KILL( blk->kl , aa->ch   ) ;
00450          }
00451          break ;
00452       }  /* end of switch */
00453 
00454    } else {  /* this is a new attribute name for this datablock */
00455 
00456       int ia ;
00457 
00458       for( ia=0 ; ia < blk->natr ; ia++ )     /* 29 April 1998: look for an */
00459          if( blk->atr[ia].type < 0 ) break ;  /* unused one before the end  */
00460 
00461       if( ia == blk->natr_alloc ){            /* need to extend array */
00462          blk->natr_alloc  += ATR_ALLINC ;
00463          blk->atr          = (ATR_any *)
00464                              XtRealloc( (char *)blk->atr,
00465                                         sizeof(ATR_any) * blk->natr_alloc );
00466       }
00467       atr = &(blk->atr[ia]) ;
00468       if( ia == blk->natr ) (blk->natr)++ ;
00469    }
00470 
00471    /* at this point, atr points to the location to store the data;
00472       now, allocate space for the actual data and store it */
00473 
00474    switch( atype ){
00475 
00476       case ATR_FLOAT_TYPE:{
00477          ATR_float *new_atr = (ATR_float *) atr ;
00478 
00479          new_atr->type = ATR_FLOAT_TYPE ;
00480          new_atr->name = XtNewString( aname ) ;
00481          new_atr->nfl  = acount ;
00482          new_atr->fl   = (float *) XtMalloc( sizeof(float) * acount ) ;
00483          memcpy( new_atr->fl , ar , sizeof(float)*acount ) ;
00484 
00485          ADDTO_KILL( blk->kl , new_atr->name ) ;
00486          ADDTO_KILL( blk->kl , new_atr->fl ) ;
00487       }
00488       break ;
00489 
00490       case ATR_INT_TYPE:{
00491          ATR_int *new_atr = (ATR_int *) atr ;
00492 
00493          new_atr->type = ATR_INT_TYPE ;
00494          new_atr->name = XtNewString( aname ) ;
00495          new_atr->nin  = acount ;
00496          new_atr->in   = (int *) XtMalloc( sizeof(int) * acount ) ;
00497          memcpy( new_atr->in , ar , sizeof(int)*acount ) ;
00498 
00499          ADDTO_KILL( blk->kl , new_atr->name ) ;
00500          ADDTO_KILL( blk->kl , new_atr->in ) ;
00501 
00502 #if 0
00503 if(PRINT_TRACING){
00504   char str[256] ; int ii ;
00505   sprintf(str,"INT atr: name=%s nin=%d vals::",new_atr->name,new_atr->nin) ;
00506   STATUS(str) ;
00507   for( ii=0 ; ii < acount ; ii++ ) printf(" %d",new_atr->in[ii]) ;
00508   printf("\n") ;
00509 }
00510 #endif
00511       }
00512       break ;
00513 
00514       case ATR_STRING_TYPE:{
00515          ATR_string *new_atr = (ATR_string *) atr ;
00516 
00517          new_atr->type = ATR_STRING_TYPE ;
00518          new_atr->name = XtNewString( aname ) ;
00519          new_atr->nch  = acount ;
00520          new_atr->ch   = (char *) XtMalloc( sizeof(char) * acount ) ;
00521          memcpy( new_atr->ch , ar , sizeof(char)*acount ) ;
00522          new_atr->ch[acount-1] = '\0' ;
00523 
00524          ADDTO_KILL( blk->kl , new_atr->name ) ;
00525          ADDTO_KILL( blk->kl , new_atr->ch ) ;
00526       }
00527       break ;
00528    }  /* end of switch */
00529 
00530    EXRETURN ;
00531 }

void THD_set_char_atr THD_datablock  ,
char *   ,
int   ,
char *   
 

Definition at line 551 of file thd_atr.c.

References ATR_STRING_TYPE, name, and THD_set_atr().

Referenced by DRAW_copy_dset(), THD_dblkatr_from_niml(), and THD_set_dataset_attributes().

00553 {
00554    THD_set_atr( blk , name , ATR_STRING_TYPE , n , str ) ;
00555 }

void THD_set_dataset_attributes THD_3dim_dataset   dset
 

Set attributes from the dataset to the datablock, preparing for output to someplace or other. Adapted from elements of the earlier editions of THD_write_3dim_dataset() and THD_write_datablock() -- 09 Mar 2005. ---------------------------------------------------------------------

Definition at line 33 of file thd_dsetatr.c.

References THD_marker_set::aflags, AFMALL, THD_3dim_dataset::anat_parent_idcode, THD_3dim_dataset::anat_parent_name, ATRNAME_ANATOMY_PARENT, ATRNAME_BRICK_FLTFAC, ATRNAME_BRICK_KEYWORDS, ATRNAME_BRICK_LABS, ATRNAME_BRICK_STATAUX, ATRNAME_BRICK_STATS, ATRNAME_BRICK_TYPES, ATRNAME_DATANAME, ATRNAME_DATASET_DIMENSIONS, ATRNAME_DATASET_RANK, ATRNAME_DELTA, ATRNAME_IDANATPAR, ATRNAME_IDDATE, ATRNAME_IDSTRING, ATRNAME_IDWARPPAR, ATRNAME_KEYWORDS, ATRNAME_LABEL1, ATRNAME_LABEL2, ATRNAME_MARKSFLAG, ATRNAME_MARKSHELP, ATRNAME_MARKSLAB, ATRNAME_MARKSXYZ, ATRNAME_ORIENT_SPECIFIC, ATRNAME_ORIGIN, ATRNAME_SCENE_TYPE, ATRNAME_STAT_AUX, ATRNAME_TAGSET_FLOATS, ATRNAME_TAGSET_LABELS, ATRNAME_TAGSET_NUM, ATRNAME_TAXIS_FLOATS, ATRNAME_TAXIS_NUMS, ATRNAME_TAXIS_OFFSETS, ATRNAME_TYPESTRING, ATRNAME_WARP_DATA, ATRNAME_WARP_PARENT, ATRNAME_WARP_TYPE, ATRSIZE_DATASET_DIMENSIONS, ATRSIZE_DATASET_RANK, ATRSIZE_DELTA, ATRSIZE_MARKSFLAG, ATRSIZE_MARKSHELP, ATRSIZE_MARKSLAB, ATRSIZE_MARKSXYZ, ATRSIZE_ORIENT_SPECIFIC, ATRSIZE_ORIGIN, ATRSIZE_SCENE_TYPE, ATRSIZE_TAXIS_FLOATS, ATRSIZE_TAXIS_NUMS, ATRSIZE_WARP_TYPE, THD_datablock::brick_fac, THD_datablock::brick_keywords, THD_datablock::brick_lab, THD_datablock::brick_stataux, THD_datablock::brick_statcode, THD_statistics::bstat, calloc, COPY_FROM_STRUCT, MCW_idcode::date, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DBLK_BRICK_TYPE, THD_diskptr::dimsizes, THD_datablock::diskptr, DSET_FIX_NAMES, THD_timeaxis::dz_sl, ENTRY, far, FFILL, FFILL_DIM, free, FTFILL, FUNC_IS_STAT, THD_3dim_dataset::func_type, THD_marker_set::help, THD_3dim_dataset::idcode, IFILL_DIM, ilen, ISVALID_3DIM_DATASET, ISVALID_DATABLOCK, ISVALID_DISKPTR, ISVALID_STATISTIC, ISZERO_IDCODE, ITFILL, THD_3dim_dataset::keywords, THD_marker_set::label, THD_usertag::label, THD_3dim_dataset::label1, THD_3dim_dataset::label2, malloc, MAPPING_LINEAR_FSIZE, MAPPING_LINEAR_FSTART, THD_3dim_dataset::markers, MARKS_MAXNUM, THD_brick_stats::max, MAX_STAT_AUX, THD_brick_stats::min, THD_statistics::nbstat, NI_stat_encode(), THD_timeaxis::nsl, THD_timeaxis::ntt, THD_usertaglist::num, THD_datablock::nvals, THD_diskptr::nvals, nz, THD_diskptr::rank, realloc, THD_affine_warp::resam_type, THD_talairach_12_warp::resam_type, THD_3dim_dataset::self_name, THD_usertag::set, THD_3dim_dataset::stat_aux, THD_3dim_dataset::stats, MCW_idcode::str, THD_usertaglist::tag, THD_3dim_dataset::tagset, THD_3dim_dataset::taxis, THD_anonymize_dset(), THD_erase_one_atr(), THD_set_char_atr(), THD_set_float_atr(), THD_set_int_atr(), THD_set_string_atr, THD_usertag::ti, THD_timeaxis::toff_sl, THD_timeaxis::ttdel, THD_timeaxis::ttdur, THD_timeaxis::ttorg, THD_3dim_dataset::type, THD_warp::type, THD_timeaxis::units_type, THD_usertag::val, THD_marker_set::valid, THD_3dim_dataset::view_type, THD_3dim_dataset::warp, THD_affine_warp::warp, THD_talairach_12_warp::warp, WARP_AFFINE_TYPE, THD_3dim_dataset::warp_parent_idcode, THD_3dim_dataset::warp_parent_name, WARP_TALAIRACH_12_SIZE, WARP_TALAIRACH_12_TYPE, THD_usertag::x, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_marker_set::xyz, THD_usertag::y, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::yyorient, THD_usertag::z, THD_timeaxis::zorg_sl, THD_dataxes::zzdel, THD_dataxes::zzorg, and THD_dataxes::zzorient.

Referenced by THD_nimlize_dsetatr(), and THD_write_3dim_dataset().

00034 {
00035    THD_datablock *blk ;
00036    THD_dataxes   *daxes ;
00037    THD_diskptr   *dkptr ;
00038 
00039    int itemp[IFILL_DIM] , ii ;
00040    float ftemp[FFILL_DIM] ;
00041 
00042    int id , nx , ny , nz , nv , nxy , nxyz , ibr , nb ;
00043    int atrank[ATRSIZE_DATASET_RANK] , atdims[ATRSIZE_DATASET_DIMENSIONS] ;
00044    MRI_IMAGE *im ;
00045    int save_order ;
00046 
00047 ENTRY("THD_set_dataset_attributes") ;
00048 
00049    /*-- sanity checks --*/
00050 
00051    if( ! ISVALID_3DIM_DATASET(dset)    ||
00052        ! ISVALID_DATABLOCK(dset->dblk) ||
00053        ! ISVALID_DISKPTR(dset->dblk->diskptr) ) EXRETURN ;
00054 
00055    blk = dset->dblk ; daxes = dset->daxes ;  /* always used fixed daxes */
00056    dkptr = blk->diskptr ;
00057 
00058    /******/
00059    /****** These attributes used to be set in THD_write_3dim_dataset() *****/
00060    /******/
00061 
00062    /*----- write TYPESTRING attribute -----*/
00063 
00064    THD_set_string_atr( blk , ATRNAME_TYPESTRING ,
00065                        DATASET_typestr[dset->type] ) ;
00066 
00067    /*----- write IDCODE attributes -----*/
00068 
00069    THD_set_string_atr( blk , ATRNAME_IDSTRING , dset->idcode.str ) ;
00070    THD_set_string_atr( blk , ATRNAME_IDDATE   , dset->idcode.date ) ;
00071 
00072    if( ! ISZERO_IDCODE(dset->anat_parent_idcode) )
00073      THD_set_string_atr( blk, ATRNAME_IDANATPAR, dset->anat_parent_idcode.str );
00074    else
00075      THD_erase_one_atr ( blk, ATRNAME_IDANATPAR ) ;
00076 
00077    if( ! ISZERO_IDCODE(dset->warp_parent_idcode) )
00078      THD_set_string_atr( blk, ATRNAME_IDWARPPAR, dset->warp_parent_idcode.str );
00079    else
00080      THD_erase_one_atr ( blk, ATRNAME_IDWARPPAR ) ;
00081 
00082    /*----- write SCENE_TYPE attribute -----*/
00083 
00084    itemp[0] = dset->view_type ;
00085    itemp[1] = dset->func_type ;
00086    itemp[2] = dset->type ;
00087 
00088    ITFILL(3,ATRSIZE_SCENE_TYPE) ;
00089    THD_set_int_atr( blk , ATRNAME_SCENE_TYPE ,
00090                           ATRSIZE_SCENE_TYPE , itemp ) ;
00091 
00092    /*----- write data labels -----*/
00093 
00094    if( strlen(dset->self_name) == 0 ) DSET_FIX_NAMES(dset) ;
00095 
00096    THD_set_string_atr( blk , ATRNAME_LABEL1   , dset->label1 ) ;
00097    THD_set_string_atr( blk , ATRNAME_LABEL2   , dset->label2 ) ;
00098    THD_set_string_atr( blk , ATRNAME_DATANAME , dset->self_name ) ;
00099 
00100    if( dset->keywords != NULL )
00101       THD_set_string_atr( blk , ATRNAME_KEYWORDS , dset->keywords ) ;
00102    else
00103       THD_erase_one_atr ( blk , ATRNAME_KEYWORDS ) ;
00104 
00105    /*----- write parent names, if they exist -----*/
00106 
00107    if( strlen(dset->warp_parent_name) > 0 )
00108       THD_set_string_atr( blk , ATRNAME_WARP_PARENT ,
00109                           dset->warp_parent_name ) ;
00110    else
00111       THD_erase_one_atr ( blk , ATRNAME_WARP_PARENT ) ;
00112 
00113    if( strlen(dset->anat_parent_name) > 0 )
00114       THD_set_string_atr( blk , ATRNAME_ANATOMY_PARENT ,
00115                           dset->anat_parent_name ) ;
00116    else
00117       THD_erase_one_atr ( blk , ATRNAME_ANATOMY_PARENT ) ;
00118 
00119    /*----- write axes orientation -----*/
00120 
00121    itemp[0] = daxes->xxorient ;
00122    itemp[1] = daxes->yyorient ;
00123    itemp[2] = daxes->zzorient ;
00124 
00125    ITFILL(3,ATRSIZE_ORIENT_SPECIFIC) ;
00126    THD_set_int_atr( blk , ATRNAME_ORIENT_SPECIFIC ,
00127                           ATRSIZE_ORIENT_SPECIFIC , itemp ) ;
00128 
00129    /*----- write axes origin -----*/
00130 
00131    ftemp[0] = daxes->xxorg ;
00132    ftemp[1] = daxes->yyorg ;
00133    ftemp[2] = daxes->zzorg ;
00134 
00135    FTFILL(3,ATRSIZE_ORIGIN) ;
00136    THD_set_float_atr( blk , ATRNAME_ORIGIN ,
00137                             ATRSIZE_ORIGIN , ftemp ) ;
00138 
00139    /*----- write axes spacings -----*/
00140 
00141    ftemp[0] = daxes->xxdel ;
00142    ftemp[1] = daxes->yydel ;
00143    ftemp[2] = daxes->zzdel ;
00144 
00145    FTFILL(3,ATRSIZE_DELTA) ;
00146    THD_set_float_atr( blk , ATRNAME_DELTA ,
00147                             ATRSIZE_DELTA , ftemp ) ;
00148 
00149    /*----- write markers, if present -----*/
00150 
00151    if( dset->markers != NULL ){
00152 
00153       for( ii=0 ; ii < MARKS_MAXNUM ; ii++ ){   /* put bad data in */
00154          if( !dset->markers->valid[ii] )        /* invalid markers */
00155             dset->markers->xyz[ii][0] =
00156             dset->markers->xyz[ii][1] =
00157             dset->markers->xyz[ii][2] = FFILL ;
00158       }
00159 
00160       THD_set_float_atr( blk , ATRNAME_MARKSXYZ ,
00161                                ATRSIZE_MARKSXYZ ,
00162                                &(dset->markers->xyz[0][0]) ) ;
00163 
00164       THD_set_char_atr( blk , ATRNAME_MARKSLAB ,
00165                               ATRSIZE_MARKSLAB ,
00166                               &(dset->markers->label[0][0]) ) ;
00167 
00168       THD_set_char_atr( blk , ATRNAME_MARKSHELP ,
00169                               ATRSIZE_MARKSHELP ,
00170                               &(dset->markers->help[0][0]) ) ;
00171 
00172       THD_set_int_atr( blk , ATRNAME_MARKSFLAG ,
00173                              ATRSIZE_MARKSFLAG ,
00174                              &(dset->markers->aflags[0]) ) ;
00175    } else {
00176       THD_erase_one_atr( blk , ATRNAME_MARKSXYZ  ) ;
00177       THD_erase_one_atr( blk , ATRNAME_MARKSLAB  ) ;
00178       THD_erase_one_atr( blk , ATRNAME_MARKSHELP ) ;
00179       THD_erase_one_atr( blk , ATRNAME_MARKSFLAG ) ;
00180    }
00181 
00182    /*----- write warp, if present -----*/
00183 
00184    if( dset->warp != NULL ){
00185       int wdata_size = 0 ;
00186 
00187       switch( dset->warp->type ){
00188 
00189          case WARP_AFFINE_TYPE:{
00190             THD_affine_warp *ww = (THD_affine_warp *) dset->warp ;
00191             itemp[0] = WARP_AFFINE_TYPE ;
00192             itemp[1] = ww->resam_type ;
00193 
00194             wdata_size = MAPPING_LINEAR_FSIZE ;
00195             COPY_FROM_STRUCT( ww->warp ,
00196                               MAPPING_LINEAR_FSTART ,
00197                               float ,
00198                               ftemp ,
00199                               MAPPING_LINEAR_FSIZE ) ;
00200          }
00201          break ;
00202 
00203          case WARP_TALAIRACH_12_TYPE:{
00204             THD_talairach_12_warp *ww =
00205                (THD_talairach_12_warp *) dset->warp ;
00206             int iw , ioff ;
00207 
00208             itemp[0] = WARP_TALAIRACH_12_TYPE ;
00209             itemp[1] = ww->resam_type ;
00210 
00211             wdata_size = WARP_TALAIRACH_12_SIZE ;
00212 
00213             for( iw=0 ; iw < 12 ; iw++ ){
00214                ioff = iw * MAPPING_LINEAR_FSIZE ;
00215 
00216                COPY_FROM_STRUCT( ww->warp[iw] ,
00217                                  MAPPING_LINEAR_FSTART ,
00218                                  float ,
00219                                  &(ftemp[ioff]) ,
00220                                  MAPPING_LINEAR_FSIZE ) ;
00221             }
00222          }
00223          break ;
00224       } /* end of switch on warp type */
00225 
00226       ITFILL(2,ATRSIZE_WARP_TYPE) ;
00227       THD_set_int_atr( blk , ATRNAME_WARP_TYPE ,
00228                              ATRSIZE_WARP_TYPE , itemp ) ;
00229 
00230       THD_set_float_atr( blk , ATRNAME_WARP_DATA ,
00231                                wdata_size , ftemp ) ;
00232 
00233    } else {  /* no warp exists */
00234 
00235       THD_erase_one_atr( blk , ATRNAME_WARP_TYPE ) ;
00236       THD_erase_one_atr( blk , ATRNAME_WARP_DATA ) ;
00237 
00238    } /* end of if warp exists */
00239 
00240    /*----- if statistics exist, write them out (modern style of floats) -----*/
00241 
00242    if( ISVALID_STATISTIC(dset->stats) ){
00243       float *tfil ;
00244       int qq ;
00245 
00246       tfil = (float *) malloc( sizeof(float) * 2*blk->nvals ) ;
00247       if( tfil != NULL ){
00248          for( qq=0 ; qq < dset->stats->nbstat ; qq++ ){
00249             tfil[2*qq]   = dset->stats->bstat[qq].min ;
00250             tfil[2*qq+1] = dset->stats->bstat[qq].max ;
00251          }
00252          THD_set_float_atr( blk, ATRNAME_BRICK_STATS,
00253                             2*dset->stats->nbstat, tfil ) ;
00254          free( tfil ) ;
00255       }
00256    } else {
00257       THD_erase_one_atr( blk , ATRNAME_BRICK_STATS ) ;
00258    }
00259 
00260    /*----- if auxiliary statistics data exists, write them out too -----*/
00261 
00262    for( ii=MAX_STAT_AUX-1; ii>=0 && dset->stat_aux[ii]==0.0; ii-- ) ; /* nada */
00263 
00264    if( ii >= 0 ){  /* ii = largest index where stat_aux != 0 */
00265       ii++ ;       /* number of stat_aux values to save      */
00266 
00267       THD_set_float_atr( blk , ATRNAME_STAT_AUX , ii , dset->stat_aux ) ;
00268    } else {
00269       THD_erase_one_atr( blk , ATRNAME_STAT_AUX ) ;
00270    }
00271 
00272    /*----- if time-dependent data, write that stuff out too -----*/
00273 
00274    if( dset->taxis != NULL ){
00275       itemp[0] = dset->taxis->ntt ;
00276       itemp[1] = dset->taxis->nsl ;
00277       itemp[2] = dset->taxis->units_type ;  /* 21 Oct 1996 */
00278 
00279       ITFILL(3,ATRSIZE_TAXIS_NUMS) ;
00280       THD_set_int_atr( blk , ATRNAME_TAXIS_NUMS ,
00281                              ATRSIZE_TAXIS_NUMS , itemp ) ;
00282 
00283       ftemp[0] = dset->taxis->ttorg ;
00284       ftemp[1] = dset->taxis->ttdel ;
00285       ftemp[2] = dset->taxis->ttdur ;
00286       ftemp[3] = dset->taxis->zorg_sl ;
00287       ftemp[4] = dset->taxis->dz_sl ;
00288 
00289       FTFILL(5,ATRSIZE_TAXIS_FLOATS) ;
00290       THD_set_float_atr( blk , ATRNAME_TAXIS_FLOATS ,
00291                                ATRSIZE_TAXIS_FLOATS , ftemp ) ;
00292 
00293       if( dset->taxis->toff_sl != NULL )
00294          THD_set_float_atr( blk , ATRNAME_TAXIS_OFFSETS ,
00295                                   dset->taxis->nsl , dset->taxis->toff_sl ) ;
00296    } else {
00297       THD_erase_one_atr( blk , ATRNAME_TAXIS_NUMS    ) ;
00298       THD_erase_one_atr( blk , ATRNAME_TAXIS_FLOATS  ) ;
00299       THD_erase_one_atr( blk , ATRNAME_TAXIS_OFFSETS ) ;
00300    }
00301 
00302    /*----- 23 Oct 1998: write out tagset, if present -----*/
00303 
00304 #undef  NFPER
00305 #define NFPER 5
00306 #define TF(i,j) vtag[(i)*NFPER+(j)]
00307    if( dset->tagset != NULL && dset->tagset->num > 0 ){
00308       int ii , ntag=dset->tagset->num , tlen,ilen,jj ;
00309       float *vtag = (float *) malloc( sizeof(float) * (NFPER*ntag) ) ;
00310       char *ctag ;
00311 
00312       /* set the counts */
00313 
00314       itemp[0] = ntag ;
00315       itemp[1] = NFPER ;
00316       THD_set_int_atr( blk , ATRNAME_TAGSET_NUM , 2 , itemp ) ;
00317 
00318       /* set the values */
00319 
00320       for( ii=0 ; ii < ntag ; ii++ ){
00321          TF(ii,0) = dset->tagset->tag[ii].x ;
00322          TF(ii,1) = dset->tagset->tag[ii].y ;
00323          TF(ii,2) = dset->tagset->tag[ii].z ;
00324          TF(ii,3) = dset->tagset->tag[ii].val ;
00325          if( dset->tagset->tag[ii].set ) TF(ii,4) = dset->tagset->tag[ii].ti ;
00326          else                            TF(ii,4) = -1.0 ;
00327       }
00328       THD_set_float_atr( blk , ATRNAME_TAGSET_FLOATS , NFPER*ntag , vtag ) ;
00329       free(vtag) ;
00330 
00331       /* set the labels */
00332 
00333       tlen = 4 ;                                       /* a little slop space */
00334       for( ii=0 ; ii < ntag ; ii++ )
00335         tlen += strlen( dset->tagset->tag[ii].label ) + 1; /* +1 for the '\0' */
00336 
00337       ctag = (char *) malloc( sizeof(char) * tlen ) ;   /* to hold all labels */
00338       jj   = 0 ;
00339       for( ii=0 ; ii < ntag ; ii++ ){
00340          ilen = strlen( dset->tagset->tag[ii].label ) + 1 ;
00341          memcpy( ctag+jj , dset->tagset->tag[ii].label , ilen ) ;
00342          jj += ilen ;
00343       }
00344       THD_set_char_atr( blk , ATRNAME_TAGSET_LABELS , tlen , ctag ) ;
00345       free(ctag) ;
00346    } else {
00347       THD_erase_one_atr( blk , ATRNAME_TAGSET_NUM    ) ;
00348       THD_erase_one_atr( blk , ATRNAME_TAGSET_LABELS ) ;
00349       THD_erase_one_atr( blk , ATRNAME_TAGSET_FLOATS ) ;
00350    }
00351 #undef NFPER
00352 #undef TF
00353 
00354    /******/
00355    /****** These attributes used to be set in THD_write_datablock() *****/
00356    /******/
00357 
00358    /* dataset dimensions */
00359 
00360    atrank[0] = dkptr->rank ;  /* should always be 3 */
00361    atrank[1] = dkptr->nvals ;
00362    for( id=2 ; id < ATRSIZE_DATASET_RANK ; id++ ) atrank[id] = 0 ;
00363 
00364    THD_set_int_atr( blk , ATRNAME_DATASET_RANK ,
00365                           ATRSIZE_DATASET_RANK , atrank ) ;
00366 
00367    for( id=0 ; id < ATRSIZE_DATASET_DIMENSIONS ; id++ )
00368      atdims[id] = (id < dkptr->rank) ? dkptr->dimsizes[id] : 0 ;
00369 
00370    THD_set_int_atr( blk , ATRNAME_DATASET_DIMENSIONS ,
00371                           ATRSIZE_DATASET_DIMENSIONS , atdims ) ;
00372 
00373    /* sub-brick types */
00374 
00375    { int *datum_type ;
00376      datum_type = AFMALL(int, sizeof(int) * blk->nvals ) ;
00377      for( id=0 ; id < blk->nvals ; id++ )
00378         datum_type[id] = DBLK_BRICK_TYPE(blk,id) ;
00379      THD_set_int_atr(   blk , ATRNAME_BRICK_TYPES  , blk->nvals , datum_type ) ;
00380      free( datum_type ) ;
00381    }
00382    THD_set_float_atr( blk, ATRNAME_BRICK_FLTFAC, blk->nvals, blk->brick_fac ) ;
00383 
00384    /** 30 Nov 1997: write out brick labels **/
00385 
00386    if( blk->brick_lab != NULL ){
00387 
00388       int ibr , nch , ipos , ll ;
00389       char *car ;
00390 
00391       for( ibr=0,nch=0 ; ibr < blk->nvals ; ibr++ ) /* total length  */
00392          nch += strlen(blk->brick_lab[ibr]) + 1 ;   /* of all labels */
00393 
00394       car = (char *) malloc( sizeof(char) * nch ) ; /* space for all labels */
00395 
00396       for( ibr=0,ipos=0 ; ibr < blk->nvals ; ibr++ ){ /* put all labels */
00397          ll = strlen(blk->brick_lab[ibr]) + 1 ;       /* together       */
00398          memcpy( car+ipos , blk->brick_lab[ibr] , ll ) ;
00399          ipos += ll ;
00400       }
00401 
00402       THD_set_char_atr( blk , ATRNAME_BRICK_LABS , nch , car ) ;
00403       free(car) ;
00404    } else {
00405       THD_erase_one_atr( blk , ATRNAME_BRICK_LABS ) ;
00406    }
00407 
00408    /** and write out brick keywords **/
00409 
00410    if( blk->brick_keywords != NULL ){
00411 
00412       int ibr , nch , ipos , ll ;
00413       char *car ;
00414 
00415       for( ibr=0,nch=0 ; ibr < blk->nvals ; ibr++ ){
00416         if( blk->brick_keywords[ibr] != NULL )
00417           nch += strlen(blk->brick_keywords[ibr]) + 1 ;
00418         else
00419           nch += 1 ;
00420       }
00421 
00422       car = (char *) malloc( sizeof(char) * nch ) ;
00423 
00424       for( ibr=0,ipos=0 ; ibr < blk->nvals ; ibr++ ){
00425         if( blk->brick_keywords[ibr] != NULL ){
00426           ll = strlen(blk->brick_keywords[ibr]) + 1 ;
00427           memcpy( car+ipos , blk->brick_keywords[ibr] , ll ) ;
00428           ipos += ll ;
00429         } else {
00430           car[ipos++] = '\0' ;
00431         }
00432       }
00433 
00434       THD_set_char_atr( blk , ATRNAME_BRICK_KEYWORDS , nch , car ) ;
00435       free(car) ;
00436    } else {
00437       THD_erase_one_atr( blk , ATRNAME_BRICK_KEYWORDS ) ;
00438    }
00439 
00440    /* and write out brick stataux parameters */
00441 
00442    if( blk->brick_statcode != NULL &&    /* write out brick stataux */
00443        blk->brick_stataux  != NULL   ){  /* stuff, if it exists.    */
00444 
00445       int ibr , nfl , jv , ipos , iv ;
00446       float *far ;
00447 
00448       for( ibr=0,nfl=0 ; ibr < blk->nvals ; ibr++ ){    /* compute total */
00449          jv = blk->brick_statcode[ibr] ;                /* space needed  */
00450          if( FUNC_IS_STAT(jv) ) nfl += FUNC_need_stat_aux[jv] + 3 ;
00451       }
00452 
00453       if( nfl > 0 ){
00454          far = (float *) malloc( sizeof(float) * nfl ) ;
00455 
00456          for( ibr=0,ipos=0 ; ibr < blk->nvals ; ibr++ ){
00457             jv = blk->brick_statcode[ibr] ;
00458             if( FUNC_IS_STAT(jv) ){
00459               far[ipos++] = ibr ;                     /* save index */
00460               far[ipos++] = jv ;                      /* save statcode */
00461               far[ipos++] = FUNC_need_stat_aux[jv] ;  /* save # of params */
00462 
00463               if( blk->brick_stataux[ibr] != NULL ){  /* if have params, save */
00464                 for( iv=0 ; iv < FUNC_need_stat_aux[jv] ; iv++ )
00465                   far[ipos++] = blk->brick_stataux[ibr][iv] ;
00466               } else {                                /* should never be used */
00467                 for( iv=0 ; iv < FUNC_need_stat_aux[jv] ; iv++ )
00468                   far[ipos++] = 0.0 ;
00469               }
00470             }
00471          }
00472 
00473          THD_set_float_atr( blk , ATRNAME_BRICK_STATAUX , nfl , far ) ;
00474          free(far) ;
00475       } else {
00476          THD_erase_one_atr( blk , ATRNAME_BRICK_STATAUX ) ;
00477       }
00478    } else {
00479       THD_erase_one_atr( blk , ATRNAME_BRICK_STATAUX ) ;
00480    }
00481 
00482    /** 01 Jun 2005: save brick_stataux stuff in a different way **/
00483 
00484    if( blk->brick_statcode != NULL &&    /* write out brick stataux */
00485        blk->brick_stataux  != NULL   ){  /* stuff, if it exists.    */
00486 
00487      int ibr , jv ;
00488 
00489      for( ibr=0 ; ibr < blk->nvals ; ibr++ ){  /* see if any bricks */
00490        jv = blk->brick_statcode[ibr] ;         /* have stat codes */
00491        if( FUNC_IS_STAT(jv) ) break ;
00492      }
00493 
00494      if( ibr < blk->nvals ){             /* got someone to save */
00495        char *statsym=(char *)calloc(1,1), *sstr ; float p1,p2,p3 ; int np ;
00496 
00497        for( ibr=0 ; ibr < blk->nvals ; ibr++ ){
00498          jv = blk->brick_statcode[ibr] ;         /* have stat codes */
00499          if( FUNC_IS_STAT(jv) ){
00500            p1 = p2 = p3 = 0.0f ;
00501            np = FUNC_need_stat_aux[jv] ;
00502            if( blk->brick_stataux[ibr] != NULL ){
00503              if( np > 0 ) p1 = blk->brick_stataux[ibr][0] ;
00504              if( np > 1 ) p2 = blk->brick_stataux[ibr][1] ;
00505              if( np > 2 ) p3 = blk->brick_stataux[ibr][2] ;
00506            }
00507            sstr = NI_stat_encode( jv , p1,p2,p3 ) ;
00508          } else {
00509            sstr = strdup("none") ;
00510          }
00511          jv = strlen(sstr) + strlen(statsym) + 4 ;
00512          statsym = (char *)realloc( statsym , jv ) ;
00513          if( ibr > 0 ) strcat(statsym,";") ;
00514          strcat(statsym,sstr) ; free(sstr) ;
00515        }
00516        THD_set_string_atr( blk , "BRICK_STATSYM" , statsym ) ;
00517        free(statsym) ;
00518      } else {
00519        THD_erase_one_atr( blk , "BRICK_STATSYM" ) ;
00520      }
00521    } else {
00522      THD_erase_one_atr( blk , "BRICK_STATSYM" ) ;
00523    }
00524 
00525    /******/
00526    /****** N.B.: we do NOT set the byte order attribute here *****/
00527    /******/ 
00528 
00529    if( anonymize ) THD_anonymize_dset(dset) ;  /* 08 Jul 2005 */
00530 
00531    EXRETURN ;
00532 }

void THD_set_float_atr THD_datablock  ,
char *   ,
int   ,
float *   
 

Definition at line 535 of file thd_atr.c.

References ATR_FLOAT_TYPE, name, and THD_set_atr().

Referenced by main(), THD_dblkatr_from_niml(), and THD_set_dataset_attributes().

00537 {
00538    THD_set_atr( blk , name , ATR_FLOAT_TYPE , n , fl ) ;
00539 }

void THD_set_freeup generic_func  
 

Definition at line 100 of file thd_loaddblk.c.

References freeup, and generic_func.

Referenced by main().

00100 { freeup = ff; }

void THD_set_int_atr THD_datablock  ,
char *   ,
int   ,
int *   
 

Definition at line 543 of file thd_atr.c.

References ATR_INT_TYPE, name, and THD_set_atr().

Referenced by T3D_save_file_CB(), THD_dblkatr_from_niml(), THD_set_dataset_attributes(), and tross_Add_Note().

00545 {
00546    THD_set_atr( blk , name , ATR_INT_TYPE , n , in ) ;
00547 }

void THD_set_storage_mode THD_3dim_dataset   dset,
int    mm
 

Mark a dataset's storage mode. -------------------------------------------------------------------

Definition at line 227 of file thd_3Ddset.c.

References THD_3dim_dataset::dblk, THD_datablock::diskptr, ISVALID_DSET, LAST_STORAGE_MODE, and THD_diskptr::storage_mode.

00228 {
00229    if( !ISVALID_DSET(dset)         ||
00230        mm < 0                      ||
00231        mm > LAST_STORAGE_MODE      ||
00232        dset->dblk == NULL          ||
00233        dset->dblk->diskptr == NULL   ) return ;
00234 
00235    dset->dblk->diskptr->storage_mode = mm ;
00236 }

void THD_set_write_compression int    mm
 

Definition at line 14 of file thd_writedblk.c.

References COMPRESS_LASTCODE, compress_mode, and COMPRESS_NONE.

Referenced by COMP_main(), ENV_compressor(), RT_tell_afni_one(), and RT_worker().

00015 {
00016    if( mm >= COMPRESS_NONE && mm <= COMPRESS_LASTCODE )
00017       compress_mode = mm ;
00018    else
00019       compress_mode = COMPRESS_NONE ;
00020    return ;
00021 }

void THD_set_write_order int   
 

Definition at line 56 of file thd_writedblk.c.

References output_order.

00057 {
00058    if( mm == LSB_FIRST || mm == MSB_FIRST )
00059       output_order = mm ;
00060    else
00061       output_order = -1 ;
00062    return ;
00063 }

FD_brick** THD_setup_bricks THD_3dim_dataset  
 

Definition at line 20 of file thd_fdbrick.c.

References CURRENT_DAXES, ISVALID_3DIM_DATASET, ISVALID_DATAXES, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, THD_3dim_dataset_to_brick(), THD_FATAL_ERROR, XtMalloc, THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by AFNI_setup_viewing(), and main().

00021 {
00022    int r2l=0 , a2p=0 , i2s=0 ;
00023    THD_dataxes * daxes ;
00024    FD_brick ** br ;
00025 
00026    if( ! ISVALID_3DIM_DATASET(dset) ) return NULL ;
00027 
00028    daxes = CURRENT_DAXES(dset) ;
00029    if( ! ISVALID_DATAXES(daxes) ) return NULL ;
00030 
00031    /*----- create FD_bricks for viewing purposes -----*/
00032 
00033    switch( daxes->xxorient ){
00034       case ORI_R2L_TYPE: r2l =  1 ; break ;
00035       case ORI_L2R_TYPE: r2l = -1 ; break ;
00036       case ORI_P2A_TYPE: a2p = -1 ; break ;
00037       case ORI_A2P_TYPE: a2p =  1 ; break ;
00038       case ORI_I2S_TYPE: i2s =  1 ; break ;
00039       case ORI_S2I_TYPE: i2s = -1 ; break ;
00040    }
00041 
00042    switch( daxes->yyorient ){
00043       case ORI_R2L_TYPE: r2l =  2 ; break ;
00044       case ORI_L2R_TYPE: r2l = -2 ; break ;
00045       case ORI_P2A_TYPE: a2p = -2 ; break ;
00046       case ORI_A2P_TYPE: a2p =  2 ; break ;
00047       case ORI_I2S_TYPE: i2s =  2 ; break ;
00048       case ORI_S2I_TYPE: i2s = -2 ; break ;
00049    }
00050 
00051    switch( daxes->zzorient ){
00052       case ORI_R2L_TYPE: r2l =  3 ; break ;
00053       case ORI_L2R_TYPE: r2l = -3 ; break ;
00054       case ORI_P2A_TYPE: a2p = -3 ; break ;
00055       case ORI_A2P_TYPE: a2p =  3 ; break ;
00056       case ORI_I2S_TYPE: i2s =  3 ; break ;
00057       case ORI_S2I_TYPE: i2s = -3 ; break ;
00058    }
00059 
00060    if( r2l==0 || a2p==0 || i2s==0 ){
00061       char buf[256] ;
00062       sprintf(buf,"Illegal orientation codes: %d %d %d",
00063                   daxes->xxorient,daxes->yyorient,daxes->zzorient ) ;
00064       THD_FATAL_ERROR(buf) ;
00065    }
00066 
00067    /* now we can set up views: axial, sagittal, coronal;
00068       the top option is the way I think it ought to be, so that
00069       in the axial and coronal views, left is left and right is right;
00070       the bottom options are the radiologists conventions, so sue me! */
00071 
00072    br = (FD_brick **) XtMalloc( sizeof(FD_brick *) * 3 ) ;
00073 
00074 #undef LEFT_IS_LEFT
00075 #ifdef LEFT_IS_LEFT
00076       br[0] = THD_3dim_dataset_to_brick(dset,-r2l, a2p,-i2s); /* axi */
00077       br[1] = THD_3dim_dataset_to_brick(dset, a2p,-i2s,-r2l); /* sag */
00078       br[2] = THD_3dim_dataset_to_brick(dset,-r2l,-i2s,-a2p); /* cor */
00079 #else
00080       br[0] = THD_3dim_dataset_to_brick(dset, r2l, a2p, i2s); /* axi */
00081       br[1] = THD_3dim_dataset_to_brick(dset, a2p,-i2s,-r2l); /* sag */
00082       br[2] = THD_3dim_dataset_to_brick(dset, r2l,-i2s, a2p); /* cor */
00083 #endif
00084 
00085    strcpy( br[0]->namecode , "Axial" ) ;
00086    strcpy( br[1]->namecode , "Sagittal" ) ;
00087    strcpy( br[2]->namecode , "Coronal" ) ;
00088 
00089    return br ;
00090 }

float THD_spearman_corr int   ,
float *   ,
float *   
 

Definition at line 136 of file thd_correlate.c.

References spearman_rank_corr(), and spearman_rank_prepare().

Referenced by main().

00137 {
00138    float xv = spearman_rank_prepare(n,x) ;
00139    if( xv <= 0.0 ) return 0.0 ;
00140    return spearman_rank_corr( n,y,xv,x ) ;
00141 }

float THD_stat_to_pval float    thr,
int    statcode,
float *    stataux
 

Definition at line 16 of file thd_statpval.c.

00017 {
00018    float pval = -1.0 ;   /* error flag */
00019 
00020    if( stataux == NULL && statcode != FUNC_ZT_TYPE ) return pval ;
00021 
00022    if( thr == 0.0 ) return 1.0 ;
00023 
00024    switch( statcode ){  /* if statcode is illegal, will return -1 */
00025 
00026       case FUNC_COR_TYPE:
00027          pval = correl_t2p( thr , stataux[0] , stataux[1] , stataux[2] ) ;
00028       break ;
00029 
00030       case FUNC_TT_TYPE:
00031          pval = student_t2p( thr , stataux[0] ) ;
00032       break ;
00033 
00034       case FUNC_FT_TYPE:
00035          pval = fstat_t2p( thr , stataux[0] , stataux[1] ) ;
00036       break ;
00037 
00038       case FUNC_ZT_TYPE:               /* only type that doesn't */
00039          pval = normal_t2p( thr ) ;    /* use stataux parameters */
00040       break ;
00041 
00042       case FUNC_CT_TYPE:
00043          pval = chisq_t2p( thr , stataux[0] ) ;
00044       break ;
00045 
00046       case FUNC_BT_TYPE:
00047          pval = beta_t2p( thr , stataux[0] , stataux[1] ) ;
00048       break ;
00049 
00050       case FUNC_BN_TYPE:
00051          pval = binomial_t2p( thr , stataux[0] , stataux[1] ) ;
00052       break ;
00053 
00054       case FUNC_GT_TYPE:
00055          pval = gamma_t2p( thr , stataux[0] , stataux[1] ) ;
00056       break ;
00057 
00058       case FUNC_PT_TYPE:
00059          pval = poisson_t2p( thr , stataux[0] ) ;
00060       break ;
00061    }
00062 
00063    return pval ;
00064 }

float THD_stat_to_zscore float    thr,
int    statcode,
float *    stataux
 

the routines below are in mri_stats.c *

Definition at line 122 of file thd_statpval.c.

00123 {
00124    float zscore = thr ;
00125 
00126    if( stataux == NULL && statcode != FUNC_ZT_TYPE ) return zscore ;
00127 
00128    switch( statcode ){  /* if statcode is illegal, will return -1 */
00129 
00130       /** the routines below are in mri_stats.c **/
00131 
00132       case FUNC_COR_TYPE:
00133          zscore = correl_t2z( thr , stataux[0] , stataux[1] , stataux[2] ) ;
00134       break ;
00135 
00136       case FUNC_TT_TYPE:
00137          zscore = student_t2z( thr , stataux[0] ) ;
00138       break ;
00139 
00140       case FUNC_FT_TYPE:
00141          zscore = fstat_t2z( thr , stataux[0] , stataux[1] ) ;
00142       break ;
00143 
00144       case FUNC_ZT_TYPE:                 /* only type that doesn't */
00145          zscore = normal_t2z( thr ) ;    /* use stataux parameters */
00146       break ;
00147 
00148       case FUNC_CT_TYPE:
00149          zscore = chisq_t2z( thr , stataux[0] ) ;
00150       break ;
00151 
00152       case FUNC_BT_TYPE:
00153          zscore = beta_t2z( thr , stataux[0] , stataux[1] ) ;
00154       break ;
00155 
00156       case FUNC_BN_TYPE:
00157          zscore = binomial_t2z( thr , stataux[0] , stataux[1] ) ;
00158       break ;
00159 
00160       case FUNC_GT_TYPE:
00161          zscore = gamma_t2z( thr , stataux[0] , stataux[1] ) ;
00162       break ;
00163 
00164       case FUNC_PT_TYPE:
00165          zscore = poisson_t2z( thr , stataux[0] ) ;
00166       break ;
00167    }
00168 
00169    return zscore ;
00170 }

void THD_store_datablock_keywords THD_datablock  ,
int   ,
char *   
 

Definition at line 164 of file thd_auxdata.c.

References THD_datablock::brick_keywords, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, and THD_init_datablock_keywords().

Referenced by EDIT_add_bricklist(), EDIT_dset_items(), THD_append_datablock_keywords(), THD_copy_datablock_auxdata(), and THD_setup_mastery().

00165 {
00166    if( ! ISVALID_DATABLOCK(dblk) || iv < 0 || iv >= dblk->nvals ) return ;
00167 
00168    if( dblk->brick_keywords == NULL ) THD_init_datablock_keywords( dblk ) ;
00169 
00170    myXtFree( dblk->brick_keywords[iv] ) ;
00171    if( str != NULL && str[0] != '\0' )
00172       dblk->brick_keywords[iv] = XtNewString( str ) ;
00173    return ;
00174 }

void THD_store_datablock_label THD_datablock  ,
int   ,
char *   
 

Definition at line 117 of file thd_auxdata.c.

References THD_datablock::brick_lab, free, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, THD_init_datablock_labels(), and XtMalloc.

Referenced by EDIT_add_bricklist(), EDIT_dset_items(), main(), THD_copy_datablock_auxdata(), and THD_setup_mastery().

00118 {
00119    char *sss ;  /* 02 Sep 2004 */
00120 
00121    if( ! ISVALID_DATABLOCK(dblk) || iv < 0 || iv >= dblk->nvals  ) return ;
00122 
00123    if( dblk->brick_lab == NULL ) THD_init_datablock_labels( dblk ) ;
00124 
00125    myXtFree( dblk->brick_lab[iv] ) ;
00126    if( str != NULL && str[0] != '\0' ){
00127       sss = strdup(str) ;
00128       if( strlen(sss) > 32 ) sss[32] = '\0' ;
00129       dblk->brick_lab[iv] = XtNewString( sss ) ;
00130       free((void *)sss) ;
00131    } else {
00132       dblk->brick_lab[iv] = (char *) XtMalloc(sizeof(char)*8) ;
00133       sprintf( dblk->brick_lab[iv] , "#%d" , iv ) ;
00134    }
00135    return ;
00136 }

void THD_store_datablock_stataux THD_datablock  ,
int   ,
int   ,
int   ,
float *   
 

Definition at line 229 of file thd_auxdata.c.

References THD_datablock::brick_stataux, THD_datablock::brick_statcode, FUNC_IS_STAT, ISVALID_DATABLOCK, myXtFree, THD_datablock::nvals, THD_init_datablock_stataux(), and XtMalloc.

Referenced by EDIT_dset_items(), THD_copy_datablock_auxdata(), THD_datablock_apply_atr(), THD_datablock_from_atr(), and THD_setup_mastery().

00231 {
00232    int kv , jv ;
00233 
00234    if( ! ISVALID_DATABLOCK(dblk) ) return ;
00235    if( iv < 0 || iv >= dblk->nvals || npar < 0 ) return ;
00236 
00237    if( dblk->brick_statcode == NULL ) THD_init_datablock_stataux( dblk ) ;
00238 
00239    dblk->brick_statcode[iv] = scode ;  /* save statcode */
00240 
00241    if( ! FUNC_IS_STAT(scode) ) return ;  /* do nothing else */
00242 
00243    /* make space, then copy data into it */
00244 
00245    kv = FUNC_need_stat_aux[scode] ;    /* how many params we need */
00246    if( npar > kv ) npar = kv ;         /* how many params we have */
00247 
00248    myXtFree( dblk->brick_stataux[iv] ) ;  /* if any old stuff, toss it */
00249 
00250    if( kv > 0 ){
00251       dblk->brick_stataux[iv] = (float *) XtMalloc( sizeof(float) * kv ) ;
00252       for( jv=0 ; jv < npar ; jv++ )
00253          dblk->brick_stataux[iv][jv] = par[jv] ; /* copy in */
00254       for( ; jv < kv ; jv++ )
00255          dblk->brick_stataux[iv][jv] = 0.0 ;     /* 0 fill */
00256    }
00257 
00258    return ;
00259 }

void THD_store_dataset_keywords THD_3dim_dataset  ,
char *   
 

Definition at line 273 of file thd_auxdata.c.

References ISVALID_3DIM_DATASET, THD_3dim_dataset::keywords, and myXtFree.

Referenced by EDIT_dset_items(), EDIT_empty_copy(), and THD_append_dataset_keywords().

00274 {
00275    if( ! ISVALID_3DIM_DATASET(dset) ) return ;
00276 
00277    myXtFree( dset->keywords ) ;
00278    if( str != NULL && str[0] != '\0' )
00279       dset->keywords = XtNewString( str ) ;
00280    return ;
00281 }

int THD_string_has char *   ,
char *   
 

Definition at line 263 of file thd_auxdata.c.

00264 {
00265    if( strbig == NULL || strbig[0] == '\0' ||
00266        strlit == NULL || strlit[0] == '\0'   ) return 0 ;
00267 
00268    return ( strstr(strbig,strlit) != NULL ) ;
00269 }

NI_element* THD_subbrick_to_niml THD_3dim_dataset   dset,
int    ival,
int    flags
 

Put a dataset sub-brick into a '<VOLUME_DATA ...>' element.

  • Returns NULL if the input is stupid. -----------------------------------------------------------------------------

Definition at line 442 of file thd_nimlatr.c.

References DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_NVALS, DSET_NVOX, ENTRY, flags, THD_3dim_dataset::idcode, ISVALID_DSET, mri_datum_size(), NI_add_column(), NI_BINARY_MODE, NI_new_data_element(), NI_set_attribute(), NI_element::outmode, RETURN, SBFLAG_FACTOR, SBFLAG_INDEX, and MCW_idcode::str.

Referenced by main(), SUMA_SendDset_Afni(), and THD_dataset_to_niml().

00443 {
00444    NI_element *nel ;
00445    char rhs[64] ;
00446    void *bar ;
00447    int  ityp , nxyz , nbar ;
00448 
00449 ENTRY("THD_subbrick_to_niml") ;
00450 
00451    if( !ISVALID_DSET(dset) ||
00452        ival < 0            || ival >= DSET_NVALS(dset) ) RETURN(NULL) ;
00453 
00454    bar  = DSET_ARRAY(dset,ival) ; if( bar == NULL ) RETURN(NULL) ;
00455 
00456    ityp = DSET_BRICK_TYPE(dset,ival) ;  /* type of data in bar */
00457    nbar = mri_datum_size(ityp) ;        /* size of one value */
00458    nxyz = DSET_NVOX(dset) ;             /* number of voxels */
00459 
00460    nel = NI_new_data_element( "VOLUME_DATA" , nxyz ) ;
00461    NI_set_attribute( nel , "domain_parent_idcode" , dset->idcode.str ) ;
00462    NI_add_column( nel , ityp , bar ) ;
00463    nel->outmode = NI_BINARY_MODE ;  /* write this in binary mode */
00464 
00465    /*-- add any special attributes desired by the caller --*/
00466 
00467    if( (flags & SBFLAG_INDEX) ){
00468      sprintf(rhs,"%d",ival) ;
00469      NI_set_attribute( nel , "index" , rhs ) ;
00470    }
00471 
00472    if( (flags & SBFLAG_FACTOR) ){
00473      float fac = DSET_BRICK_FACTOR(dset,ival) ;
00474      if( fac > 0.0 ){
00475        sprintf(rhs,"%f",fac) ;
00476        NI_set_attribute( nel , "scale_factor" , rhs ) ;
00477      }
00478    }
00479 
00480    RETURN(nel) ;
00481 }

float THD_timeof int   ,
float   ,
THD_timeaxis  
 

Definition at line 15 of file thd_timeof.c.

References THD_timeaxis::dz_sl, ISVALID_TIMEAXIS, THD_timeaxis::nsl, THD_timeaxis::toff_sl, THD_timeaxis::ttdel, THD_timeaxis::ttorg, and THD_timeaxis::zorg_sl.

Referenced by calculate_results(), FD_brick_to_series(), get_time(), initialize_slice_sequence(), MAKER_4D_to_typed_fbuc(), MAKER_4D_to_typed_fim(), MAKER_4D_to_typed_fith(), PLUTO_4D_to_nothing(), THD_extract_many_series(), and THD_extract_series().

00016 {
00017    float sl , tof ;
00018    int  isl ;
00019 
00020    if( ! ISVALID_TIMEAXIS(tax) ) return 0.0 ;
00021 
00022    tof = tax->ttorg + it * tax->ttdel ;
00023 
00024    if( tax->nsl <= 0 || tax->toff_sl == NULL ) return tof ;
00025 
00026    isl = (z - tax->zorg_sl) / tax->dz_sl + 0.5 ;
00027 
00028    if( isl < 0 || isl >= tax->nsl ) return tof ;
00029 
00030    return tof + tax->toff_sl[isl] ;
00031 }

float THD_timeof_slice int   ,
int   ,
THD_3dim_dataset  
 

Definition at line 63 of file thd_timeof.c.

References ISVALID_DSET, ISVALID_TIMEAXIS, THD_timeaxis::nsl, THD_3dim_dataset::taxis, THD_timeaxis::toff_sl, THD_timeaxis::ttdel, and THD_timeaxis::ttorg.

Referenced by cubic_spline().

00064 {
00065    float tof ;
00066 
00067    if( !ISVALID_DSET(dset) || !ISVALID_TIMEAXIS(dset->taxis) ) return 0.0 ;
00068 
00069    tof = dset->taxis->ttorg + it * dset->taxis->ttdel ;
00070 
00071    if( dset->taxis->nsl <= 0 || dset->taxis->toff_sl == NULL ) return tof ;
00072 
00073    if( isl < 0 || isl >= dset->taxis->nsl ) return tof ;
00074 
00075    return tof + dset->taxis->toff_sl[isl] ;
00076 }

float THD_timeof_vox int   ,
int   ,
THD_3dim_dataset  
 

Definition at line 38 of file thd_timeof.c.

References DSET_NX, DSET_NY, ISVALID_DSET, ISVALID_TIMEAXIS, THD_timeaxis::nsl, THD_3dim_dataset::taxis, THD_timeaxis::toff_sl, THD_timeaxis::ttdel, and THD_timeaxis::ttorg.

Referenced by main(), RT_registration_2D_onevol(), and RT_registration_3D_onevol().

00039 {
00040    float sl , tof ;
00041    int isl ;
00042 
00043    if( !ISVALID_DSET(dset) || !ISVALID_TIMEAXIS(dset->taxis) ) return 0.0 ;
00044 
00045    tof = dset->taxis->ttorg + it * dset->taxis->ttdel ;
00046 
00047    if( dset->taxis->nsl <= 0 || dset->taxis->toff_sl == NULL ) return tof ;
00048 
00049    isl = nvox / ( DSET_NX(dset) * DSET_NY(dset) ) ;
00050 
00051    if( isl < 0 || isl >= dset->taxis->nsl ) return tof ;
00052 
00053    return tof + dset->taxis->toff_sl[isl] ;
00054 }

char* THD_trailname char *    fname,
int    lev
 

Find a 'trailing name in a pathname.

For example, for fname = "/bob/cox/is/the/author/of/AFNI",

  • the lev=0 trailing name is "AFNI",
  • the lev=1 trailing name is "of/AFNI",
  • the lev=2 trailing name is "author/of/AFNI", and so on. That is, "lev" is the number of directory names above the last name to keep. The pointer returned is to some place in the middle of fname; that is, this is not a malloc()-ed string, so don't try to free() it!. -------------------------------------------------------------------

Definition at line 185 of file thd_filestuff.c.

00186 {
00187    int fpos , flen , flev ;
00188 
00189    if( fname == NULL || (flen=strlen(fname)) <= 1 ) return fname ;
00190 
00191    if( lev < 0 ) lev = 0 ;
00192 
00193    flev = 0 ;
00194    fpos = flen ;
00195    if( fname[fpos-1] == '/' ) fpos-- ;  /* skip trailing slash */
00196 
00197    /* fpos   = index of latest character I've accepted,
00198       fpos-1 = index of next character to examine,
00199       flev   = number of directory levels found so far */
00200 
00201    while( fpos > 0 ){
00202 
00203       if( fname[fpos-1] == '/' ){
00204          flev++ ; if( flev >  lev ) break ;  /* reached the lev we like */
00205       }
00206       fpos-- ;  /* scan backwards */
00207    }
00208 
00209    return (fname+fpos) ;
00210 }

THD_fvec3 THD_tta_to_mni THD_fvec3    tv
 

Convert TTA coordinates (RAI) to MNI coordinates (LPI). -------------------------------------------------------------------------

Definition at line 34 of file thd_mnicoords.c.

References LOAD_FVEC3, and THD_fvec3::xyz.

Referenced by THD_3tta_to_3mni(), and TT_whereami().

00035 {
00036    float mx,my,mz , tx,ty,tz ;
00037    THD_fvec3 mv ;
00038 
00039    tx = -tv.xyz[0] ; ty = -tv.xyz[1] ;  /* flip xy from RAI to LPI */
00040    tz =  tv.xyz[2] ;
00041 
00042    mx = 1.01010 * tx ;
00043    my = 1.02962 * ty - 0.05154 * tz ;
00044    mz = 0.05434 * ty + 1.08554 * tz ;
00045    if( mz < 0.0 ) mz *= 1.09523 ;
00046    LOAD_FVEC3( mv , mx,my,mz ) ; return mv ;
00047 }

void THD_unzblock int   ,
char *   
 

Definition at line 26 of file thd_zblock.c.

References ZBLOCK.

Referenced by THD_dblkatr_from_niml(), THD_read_all_atr(), and THD_write_atr().

00027 {
00028    int ii ;
00029    if( nch <= 0 ) return ;
00030 
00031    for( ii=0 ; ii < nch ; ii++ )
00032      if( ch[ii] == ZBLOCK ) ch[ii] = '\0' ;
00033 
00034    ch[nch-1] = '\0' ;
00035 }

void THD_update_one_bstat THD_3dim_dataset   dset,
int    iv
 

Update the statistics of one sub-brick in a dataset. [29 Mar 2005] ------------------------------------------------------------------------

Definition at line 273 of file thd_bstats.c.

References ADDTO_KILL, THD_statistics::bstat, THD_3dim_dataset::dblk, DSET_BRICK, DSET_BRICK_FACTOR, DSET_NVALS, INVALIDATE_BSTAT, ISVALID_3DIM_DATASET, ISVALID_BSTAT, THD_3dim_dataset::kl, THD_brick_stats::max, THD_brick_stats::min, myXtNew, THD_statistics::nbstat, THD_datablock::nvals, THD_statistics::parent, REPLACE_KILL, STATISTICS_TYPE, THD_3dim_dataset::stats, THD_get_brick_stats(), THD_statistics::type, and XtRealloc.

00274 {
00275    Boolean good ;
00276    int ii , mmin , mmax , ibr , nbsold , nbr ;
00277    THD_brick_stats *bsold ;
00278    short *brkk ;
00279 
00280    /*-- sanity checks --*/
00281 
00282    if( ! ISVALID_3DIM_DATASET(dset)     ) return ;
00283    if( iv < 0 || iv >= DSET_NVALS(dset) ) return ;
00284 
00285    /*-- if here, have good data in this dataset --*/
00286 
00287    if( dset->stats == NULL ){                  /* create if not present */
00288      dset->stats = myXtNew( THD_statistics ) ;
00289      ADDTO_KILL( dset->kl , dset->stats ) ;
00290      dset->stats->type   = STATISTICS_TYPE ;
00291      dset->stats->parent = (XtPointer) dset ;
00292      dset->stats->bstat  = NULL ;
00293      dset->stats->nbstat = 0 ;
00294      nbsold              = 0 ;
00295    } else {
00296      nbsold              = dset->stats->nbstat ;
00297    }
00298 
00299    if( dset->dblk->nvals > nbsold ){
00300      bsold               = dset->stats->bstat ;
00301      dset->stats->nbstat = dset->dblk->nvals ;
00302      dset->stats->bstat  = (THD_brick_stats *)
00303                            XtRealloc( (char *) bsold ,
00304                                 sizeof(THD_brick_stats) * dset->dblk->nvals ) ;
00305      if( bsold != dset->stats->bstat )
00306        REPLACE_KILL( dset->kl , bsold , dset->stats->bstat ) ;
00307 
00308      for( ibr=nbsold ; ibr < dset->dblk->nvals ; ibr++ )  /* 11 Mar 2005 */
00309        INVALIDATE_BSTAT( dset->stats->bstat[ibr] ) ;
00310    }
00311 
00312    if( iv >= nbsold || ! ISVALID_BSTAT(dset->stats->bstat[iv]) ){
00313      dset->stats->bstat[iv] = THD_get_brick_stats( DSET_BRICK(dset,iv) ) ;
00314 
00315      if( DSET_BRICK_FACTOR(dset,iv) > 0.0 ){
00316        dset->stats->bstat[iv].min *= DSET_BRICK_FACTOR(dset,iv) ;
00317        dset->stats->bstat[iv].max *= DSET_BRICK_FACTOR(dset,iv) ;
00318      }
00319    }
00320 
00321    return ;
00322 }

void THD_update_statistics THD_3dim_dataset   dset
 

Update the statistics of a dataset (use only if new bricks are added -- see EDIT_add_bricklist) ------------------------------------------------------------------------

Definition at line 211 of file thd_bstats.c.

References ADDTO_KILL, THD_statistics::bstat, THD_3dim_dataset::dblk, DSET_BRICK, DSET_BRICK_FACTOR, INVALIDATE_BSTAT, ISVALID_3DIM_DATASET, ISVALID_BSTAT, THD_3dim_dataset::kl, THD_brick_stats::max, THD_brick_stats::min, myXtNew, THD_statistics::nbstat, THD_datablock::nvals, THD_statistics::parent, REPLACE_KILL, STATISTICS_TYPE, THD_3dim_dataset::stats, THD_count_databricks(), THD_get_brick_stats(), THD_statistics::type, and XtRealloc.

Referenced by NUD_update_base(), process_NIML_AFNI_dataset(), process_NIML_AFNI_volumedata(), RT_tell_afni_one(), THD_load_datablock(), and THD_niml_to_dataset().

00212 {
00213    Boolean good ;
00214    int ii , mmin , mmax , ibr , nbsold , nbr ;
00215    THD_brick_stats *bsold ;
00216    short *brkk ;
00217 
00218    /*-- sanity checks --*/
00219 
00220    if( ! ISVALID_3DIM_DATASET(dset) ) return ;
00221 
00222    nbr = THD_count_databricks( dset->dblk ) ;
00223 
00224    if( nbr == 0 ) return ;
00225 
00226    /*-- if here, have good data in this dataset --*/
00227 
00228    if( dset->stats == NULL ){                  /* create if not present */
00229      dset->stats = myXtNew( THD_statistics ) ;
00230      ADDTO_KILL( dset->kl , dset->stats ) ;
00231      dset->stats->type   = STATISTICS_TYPE ;
00232      dset->stats->parent = (XtPointer) dset ;
00233      dset->stats->bstat  = NULL ;
00234      dset->stats->nbstat = 0 ;
00235      nbsold              = 0 ;
00236    } else {
00237      nbsold              = dset->stats->nbstat ;
00238    }
00239 
00240    if( dset->dblk->nvals > nbsold ){
00241      bsold               = dset->stats->bstat ;
00242      dset->stats->nbstat = dset->dblk->nvals ;
00243      dset->stats->bstat  = (THD_brick_stats *)
00244                            XtRealloc( (char *) bsold ,
00245                                 sizeof(THD_brick_stats) * dset->dblk->nvals ) ;
00246      if( bsold != dset->stats->bstat )
00247        REPLACE_KILL( dset->kl , bsold , dset->stats->bstat ) ;
00248 
00249      for( ibr=nbsold ; ibr < dset->dblk->nvals ; ibr++ )  /* 11 Mar 2005 */
00250        INVALIDATE_BSTAT( dset->stats->bstat[ibr] ) ;
00251    }
00252 
00253    /* 28 Apr 1997: load stats for new sub-bricks, not all */
00254 
00255    for( ibr=0 ; ibr < dset->dblk->nvals ; ibr++ ){
00256 
00257      if( ibr >= nbsold || ! ISVALID_BSTAT(dset->stats->bstat[ibr]) ){
00258         dset->stats->bstat[ibr] = THD_get_brick_stats( DSET_BRICK(dset,ibr) ) ;
00259 
00260         if( DSET_BRICK_FACTOR(dset,ibr) > 0.0 ){
00261           dset->stats->bstat[ibr].min *= DSET_BRICK_FACTOR(dset,ibr) ;
00262           dset->stats->bstat[ibr].max *= DSET_BRICK_FACTOR(dset,ibr) ;
00263         }
00264      }
00265    }
00266    return ;
00267 }

void THD_use_3D_format int   
 

Definition at line 14 of file thd_writedset.c.

References use_3D_format.

Referenced by main().

00014 { use_3D_format    = uu; }

void THD_use_NIFTI_format int   
 

Definition at line 15 of file thd_writedset.c.

References use_NIFTI_format.

00015 { use_NIFTI_format = uu; }

THD_3dim_dataset* THD_warp3D THD_3dim_dataset   inset,
void     w_in2out(float, float, float, float *, float *, float *),
void     w_out2in(float, float, float, float *, float *, float *),
void *    newggg,
char *    prefix,
int    zpad,
int    flag
 

Geometrically transform a 3D dataset, producing a new dataset.

  • w_in2out transforms DICOM coords from input grid to output grid (only needed if newggg != NULL and flag == WARP3D_NEWGRID; otherwise, w_in2out can be NULL)
  • w_out2in is the inverse of w_in2out (cannot be NULL)
  • newggg is a pointer to something that determines the new grid on which the output dataset will be computed
    • NULL means compute on the inset grid
    • otherwise, flag determines how newggg is interpreted:
    • WARP3D_NEWGRID => newggg is a "float *" to a new grid size
    • WARP3D_NEWDSET => newggg is a "THD_3dim_dataset *" to a dataset whose grid will be used for the output grid
  • prefix = new dataset prefix (if NULL, then "warped")
  • zpad = number of planes to zeropad on each face of inset (>= 0)
  • flag = see above
  • Interpolation method can be set using mri_warp3D_method().
  • At end, input dataset is unloaded from memory.
  • If input is 3D+time, the output dataset won't have slice-wise time offsets, even if the input did. ----------------------------------------------------------------------------

Definition at line 1002 of file mri_warp3D.c.

References ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DSET_BRICK, DSET_BRICK_FACTOR, DSET_delete, DSET_load, DSET_LOADED, DSET_NUM_TIMES, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_TIMEDURATION, DSET_TIMEORIGIN, DSET_TIMEUNITS, DSET_TR, DSET_unload, DSET_unload_one, EDIT_BRICK_FACTOR, EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), ENTRY, THD_3dim_dataset::func_type, THD_ivec3::ijk, INIT_STAT_AUX, INV_VECMAT, ISVALID_DSET, MRI_IMAGE::kind, LOAD_DIAG_MAT, LOAD_FVEC3, MAX_STAT_AUX, THD_vecmat::mm, mri_free(), MRI_IS_INT_TYPE, mri_scale_to_float(), mri_scalize(), mri_warp3D(), MUL_VECMAT, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_R2L_TYPE, RETURN, THD_3dim_dataset::stat_aux, THD_copy_datablock_auxdata(), THD_filename_ok(), thd_floatscan(), THD_load_statistics(), THD_zeropad(), THD_dataxes::to_dicomm, THD_3dim_dataset::type, THD_3dim_dataset::view_type, THD_vecmat::vv, w3d_warp_func(), WARP3D_GRIDMASK, WARP3D_NEWDSET, WARP3D_NEWGRID, warp_corners(), warp_out_to_in, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yyorg, ZPAD_PURGE, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by THD_warp3D_affine(), THD_warp3D_mni2tta(), and THD_warp3D_tta2mni().

01007 {
01008    THD_3dim_dataset *outset , *qset , *newgset=NULL ;
01009    int nxin,nyin,nzin,nvals , ival ;
01010    int nxout,nyout,nzout ;
01011    float xbot,xtop , ybot,ytop , zbot,ztop ;
01012    int use_newgrid , use_oldgrid ;
01013    float ddd_newgrid , fac ;
01014    MRI_IMAGE *inim , *outim , *wim ;
01015 
01016 ENTRY("THD_warp3D") ;
01017 
01018    /*-- decide which grid the output will be computed on --*/
01019 
01020    use_newgrid = ((flag & WARP3D_GRIDMASK) == WARP3D_NEWGRID) && (newggg != NULL) ;
01021    if( use_newgrid ){
01022      float *gg = (float *)newggg ;
01023      if( thd_floatscan(1,gg) == 0 && *gg > 0.0 ) ddd_newgrid = *gg ;
01024      else                                        use_newgrid = 0 ;
01025    } else if( newggg != NULL && (flag & WARP3D_GRIDMASK) == WARP3D_NEWDSET ){
01026      newgset = (THD_3dim_dataset *) newggg ;
01027      if( !ISVALID_DSET(newgset) ) newgset = NULL ;
01028    }
01029    use_oldgrid = !use_newgrid && (newgset == NULL) ;
01030 
01031    /*-- see if inputs are valid --*/
01032 
01033    if( !ISVALID_DSET(inset)             ||
01034        w_out2in == NULL                 ||
01035        (w_in2out == NULL && use_newgrid)  ){
01036 
01037      fprintf(stderr,"** ERROR: THD_warp3D has bad inputs!\n") ;
01038      RETURN(NULL);
01039    }
01040 
01041    /*-- zeropad and replace input dataset, if desired --*/
01042 
01043    if( zpad > 0 ){
01044      qset = THD_zeropad( inset , zpad,zpad,zpad,zpad,zpad,zpad ,
01045                          "Quetzalcoatl" , ZPAD_PURGE ) ;
01046      DSET_unload(inset) ;
01047      if( qset == NULL ){
01048        fprintf(stderr,"** ERROR: THD_warp3D can't zeropad!\n"); RETURN(NULL);
01049      }
01050    } else {
01051      qset = inset ;
01052    }
01053 
01054    /*-- read input data from disk, if not already present --*/
01055 
01056    DSET_load(qset) ;
01057    if( !DSET_LOADED(qset) ){
01058      fprintf(stderr,"** ERROR: THD_warp3D can't load input dataset!\n") ;
01059      if( qset != inset ) DSET_delete(qset) ; else DSET_unload(qset) ;
01060      RETURN(NULL);
01061    }
01062 
01063    /*-- compute mapping from input dataset (i,j,k) to DICOM coords --*/
01064 
01065    { THD_vecmat ijk_to_xyz , xyz_to_dicom ;
01066 
01067      LOAD_DIAG_MAT( ijk_to_xyz.mm , qset->daxes->xxdel,
01068                                     qset->daxes->yydel, qset->daxes->zzdel );
01069      LOAD_FVEC3   ( ijk_to_xyz.vv , qset->daxes->xxorg,
01070                                     qset->daxes->yyorg, qset->daxes->zzorg );
01071 
01072      xyz_to_dicom.mm = qset->daxes->to_dicomm ;
01073      LOAD_FVEC3( xyz_to_dicom.vv , 0.0,0.0,0.0 ) ;
01074 
01075      ijk_to_dicom_in = MUL_VECMAT( xyz_to_dicom , ijk_to_xyz ) ;
01076      dicom_to_ijk_in = INV_VECMAT( ijk_to_dicom_in ) ;
01077    }
01078 
01079    /*-- make empty output dataset --*/
01080 
01081    nxin  = DSET_NX(qset) ;
01082    nyin  = DSET_NY(qset) ;
01083    nzin  = DSET_NZ(qset) ;
01084    nvals = DSET_NVALS(qset) ;
01085 
01086    if( nxin*nyin*nzin <= 1 ){
01087      fprintf(stderr,"** ERROR: THD_warp3D has nxin=%d nyin=%d nzin=%d!\n",
01088              nxin,nyin,nzin ) ;
01089      if( qset != inset ) DSET_delete(qset) ; else DSET_unload(qset) ;
01090      RETURN(NULL) ;
01091    }
01092 
01093    if( use_oldgrid ){                /*-- output is on same grid as input --*/
01094 
01095      outset = EDIT_empty_copy( qset ) ;
01096 
01097    } else if( newgset != NULL ){     /*-- output on same grid as newgset --*/
01098 
01099      outset = EDIT_empty_copy( newgset ) ;
01100 
01101      EDIT_dset_items( outset ,
01102                         ADN_nvals       , nvals ,
01103                         ADN_type        , qset->type ,
01104                         ADN_view_type   , qset->view_type ,
01105                         ADN_func_type   , qset->func_type ,
01106                         ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
01107                       ADN_none ) ;
01108 
01109      if( DSET_NUM_TIMES(qset) > 1 )     /* and some time structure? */
01110        EDIT_dset_items( outset ,
01111                           ADN_ntt       , nvals ,
01112                           ADN_tunits    , DSET_TIMEUNITS(qset) ,
01113                           ADN_ttorg     , DSET_TIMEORIGIN(qset) ,
01114                           ADN_ttdel     , DSET_TR(qset) ,
01115                           ADN_ttdur     , DSET_TIMEDURATION(qset) ,
01116                         ADN_none ) ;
01117 
01118      THD_copy_datablock_auxdata( qset->dblk , outset->dblk ) ;  /* 08 Jun 2004 */
01119      INIT_STAT_AUX( qset , MAX_STAT_AUX , outset->stat_aux ) ;
01120 
01121    } else {                          /*-- output is on new grid --*/
01122 
01123      float xmid,ymid,zmid ;
01124      THD_ivec3 nxyz , orixyz ;
01125      THD_fvec3 dxyz , orgxyz ;
01126 
01127      /* compute DICOM coordinates of warped corners */
01128 
01129      warp_corners( qset, w_in2out, &xbot,&xtop, &ybot,&ytop, &zbot,&ztop ) ;
01130 
01131      nxout = (int)( (xtop-xbot)/ddd_newgrid+0.999 ); if( nxout < 1 ) nxout = 1;
01132      nyout = (int)( (ytop-ybot)/ddd_newgrid+0.999 ); if( nyout < 1 ) nyout = 1;
01133      nzout = (int)( (ztop-zbot)/ddd_newgrid+0.999 ); if( nzout < 1 ) nzout = 1;
01134 
01135      xmid = 0.5*(xbot+xtop); ymid = 0.5*(ybot+ytop); zmid = 0.5*(zbot+ztop);
01136      xbot = xmid-0.5*(nxout-1)*ddd_newgrid; xtop = xbot+(nxout-1)*ddd_newgrid;
01137      ybot = ymid-0.5*(nyout-1)*ddd_newgrid; ytop = ybot+(nyout-1)*ddd_newgrid;
01138      zbot = zmid-0.5*(nzout-1)*ddd_newgrid; ztop = zbot+(nzout-1)*ddd_newgrid;
01139 
01140 #if 0
01141      if( verb )
01142        fprintf(stderr,"++ Transformed grid:\n"
01143                       "++   xbot = %10.4g  xtop = %10.4g  nx = %d\n"
01144                       "++   ybot = %10.4g  ytop = %10.4g  ny = %d\n"
01145                       "++   zbot = %10.4g  ztop = %10.4g  nz = %d\n" ,
01146                xbot,xtop,nxout , ybot,ytop,nyout , zbot,ztop,nzout    ) ;
01147 #endif
01148 
01149      if( nxout*nyout*nzout <= 1 ){
01150        fprintf(stderr,"** ERROR: THD_warp3D has nxout=%d nyout=%d nzout=%d!\n",
01151                nxout,nyout,nzout ) ;
01152        if( qset != inset ) DSET_delete(qset) ; else DSET_unload(qset) ;
01153        RETURN(NULL) ;
01154      }
01155 
01156      nxyz.ijk[0] = nxout ; dxyz.xyz[0] = ddd_newgrid ;  /* setup axes */
01157      nxyz.ijk[1] = nyout ; dxyz.xyz[1] = ddd_newgrid ;
01158      nxyz.ijk[2] = nzout ; dxyz.xyz[2] = ddd_newgrid ;
01159 
01160      orixyz.ijk[0] = ORI_R2L_TYPE ; orgxyz.xyz[0] = xbot ;
01161      orixyz.ijk[1] = ORI_A2P_TYPE ; orgxyz.xyz[1] = ybot ;
01162      orixyz.ijk[2] = ORI_I2S_TYPE ; orgxyz.xyz[2] = zbot ;
01163 
01164      /** create dataset and mangle it into the desired shape **/
01165 
01166      outset = EDIT_empty_copy( NULL ) ;  /* void and formless dataset */
01167 
01168      EDIT_dset_items( outset ,           /* give it some structure! */
01169                         ADN_nxyz        , nxyz ,
01170                         ADN_xyzdel      , dxyz ,
01171                         ADN_xyzorg      , orgxyz ,
01172                         ADN_xyzorient   , orixyz ,
01173                         ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
01174                         ADN_nvals       , nvals ,
01175                         ADN_type        , qset->type ,
01176                         ADN_view_type   , qset->view_type ,
01177                         ADN_func_type   , qset->func_type ,
01178                       ADN_none ) ;
01179 
01180      if( DSET_NUM_TIMES(qset) > 1 )     /* and some time structure? */
01181        EDIT_dset_items( outset ,
01182                           ADN_ntt       , nvals ,
01183                           ADN_tunits    , DSET_TIMEUNITS(qset) ,
01184                           ADN_ttorg     , DSET_TIMEORIGIN(qset) ,
01185                           ADN_ttdel     , DSET_TR(qset) ,
01186                           ADN_ttdur     , DSET_TIMEDURATION(qset) ,
01187                         ADN_none ) ;
01188 
01189      THD_copy_datablock_auxdata( qset->dblk , outset->dblk ) ;  /* 08 Jun 2004 */
01190      INIT_STAT_AUX( qset , MAX_STAT_AUX , outset->stat_aux ) ;
01191 
01192    } /*-- end of warping to new grid --*/
01193 
01194    nxout = DSET_NX(outset) ;
01195    nyout = DSET_NY(outset) ;
01196    nzout = DSET_NZ(outset) ;
01197 
01198    /*-- compute mapping from output dataset (i,j,k) to DICOM coords --*/
01199 
01200    { THD_vecmat ijk_to_xyz , xyz_to_dicom ;
01201 
01202      LOAD_DIAG_MAT( ijk_to_xyz.mm, outset->daxes->xxdel,
01203                                    outset->daxes->yydel, outset->daxes->zzdel );
01204      LOAD_FVEC3   ( ijk_to_xyz.vv, outset->daxes->xxorg,
01205                                    outset->daxes->yyorg, outset->daxes->zzorg );
01206 
01207      xyz_to_dicom.mm = outset->daxes->to_dicomm ;
01208      LOAD_FVEC3( xyz_to_dicom.vv , 0.0,0.0,0.0 ) ;
01209 
01210      ijk_to_dicom_out = MUL_VECMAT( xyz_to_dicom , ijk_to_xyz ) ;
01211    }
01212 
01213    /*-- add prefix to new dataset --*/
01214 
01215    if( !THD_filename_ok(prefix) ) prefix = "warped" ;
01216    EDIT_dset_items( outset , ADN_prefix,prefix , ADN_none ) ;
01217 
01218    /*-- loop over bricks and warp them --*/
01219 
01220    warp_out_to_in = w_out2in ;  /* for use in w3d_warp_func(), supra */
01221 
01222    for( ival=0 ; ival < nvals ; ival++ ){
01223      inim  = DSET_BRICK(qset,ival) ;
01224      fac   = DSET_BRICK_FACTOR(qset,ival) ;
01225      if( fac > 0.0 && fac != 1.0 ) wim = mri_scale_to_float( fac , inim ) ;
01226      else                          wim = inim ;
01227      outim = mri_warp3D( wim , nxout,nyout,nzout , w3d_warp_func ) ;
01228      if( outim == NULL ){
01229        fprintf(stderr,"** ERROR: THD_warp3D fails at ival=%d\n",ival);
01230        DSET_delete(outset);
01231        if( qset != inset ) DSET_delete(qset) ; else DSET_unload(qset) ;
01232        RETURN(NULL) ;
01233      }
01234 
01235      if( wim != inim ){  /* if we scaled input */
01236        float gtop , fimfac ;
01237        mri_free(wim) ;
01238 
01239        /* 20 Oct 2003: rescale if input was an integer type */
01240 
01241        if( outim->kind == MRI_float && MRI_IS_INT_TYPE(inim->kind) ){
01242          fimfac = fac ;
01243          wim = mri_scalize( outim , inim->kind , &fimfac ) ;
01244          EDIT_BRICK_FACTOR( outset , ival , fimfac ) ;
01245          mri_free(outim) ; outim = wim ;
01246        } else {                                     /* input not an integer: */
01247          EDIT_BRICK_FACTOR( outset , ival , 0.0 ) ; /* output=unscaled float */
01248        }
01249 
01250      }
01251      EDIT_substitute_brick( outset, ival,outim->kind,mri_data_pointer(outim) );
01252      DSET_unload_one( qset , ival ) ;
01253    }
01254 
01255    /*-- done!!! --*/
01256 
01257    if( qset != inset ) DSET_delete(qset) ; else DSET_unload(qset) ;
01258 
01259    THD_load_statistics( outset ) ;
01260    RETURN( outset ) ;
01261 }

THD_3dim_dataset* THD_warp3D_affine THD_3dim_dataset   inset,
THD_vecmat    out2in,
void *    newggg,
char *    prefix,
int    zpad,
int    flag
 

A version of THD_warp3D() that uses an affine map, specified in the out2in parameter. The main advantage over THD_warp3D() is that the transformation functions internal -- afo2i() and afi2o() -- which makes it simpler on the caller and also somewhat faster. ----------------------------------------------------------------------------

Definition at line 1296 of file mri_warp3D.c.

References afi2o(), afo2i(), INV_VECMAT, and THD_warp3D().

Referenced by main().

01300 {
01301    aff_out2in = out2in ;
01302    aff_in2out = INV_VECMAT(aff_out2in) ;
01303 
01304    return THD_warp3D( inset , afi2o,afo2i , newggg,prefix,zpad,flag ) ;
01305 }

THD_3dim_dataset* THD_warp3D_mni2tta THD_3dim_dataset  ,
void *   ,
char *   ,
int   ,
int   
 

Definition at line 1348 of file mri_warp3D.c.

References THD_warp3D(), w3d_mni2tta(), and w3d_tta2mni().

Referenced by main().

01350 {
01351    return THD_warp3D( inset , w3d_mni2tta,w3d_tta2mni , newggg,prefix,zpad,flag ) ;
01352 }

THD_3dim_dataset* THD_warp3D_tta2mni THD_3dim_dataset  ,
void *   ,
char *   ,
int   ,
int   
 

Definition at line 1340 of file mri_warp3D.c.

References THD_warp3D(), w3d_mni2tta(), and w3d_tta2mni().

Referenced by main().

01342 {
01343    return THD_warp3D( inset , w3d_tta2mni,w3d_mni2tta , NULL,prefix,0,0 ) ;
01344 }

void THD_write_1D char *    sname,
char *    pname,
THD_3dim_dataset   dset
 

Write a dataset to disk as a 1D file. Called from THD_write_3dim_dataset(). --------------------------------------------------------------------

Definition at line 226 of file thd_1Ddset.c.

References AFNI_yesenv(), THD_diskptr::brick_name, CABS, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_STATCODE, DSET_BRICK_STATPAR, DSET_BRICK_TYPE, DSET_BRIKNAME, DSET_DX, DSET_DY, DSET_DZ, DSET_IS_1D, DSET_LOADED, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_PREFIX, DSET_TIMEUNITS, DSET_TR, DSET_XORG, DSET_YORG, DSET_ZORG, dt, ENTRY, rgbyte::g, HAS_TIMEAXIS, THD_3dim_dataset::idcode, ISVALID_DSET, NI_byteorder(), NI_LSB_FIRST, NI_stat_distname(), NI_stat_numparam(), nz, rgbyte::r, MCW_idcode::str, STRING_HAS_SUFFIX, THD_MAX_NAME, UNITS_MSEC_TYPE, THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.

Referenced by THD_write_3D(), and THD_write_3dim_dataset().

00227 {
00228    char fname[THD_MAX_NAME] , *cpt ;
00229    int iv,nv , nx,ny,nz,nxyz,ii,jj,kk ;
00230    FILE *fp=NULL ;
00231    int binflag ; char shp ; float val[1] ;
00232 
00233 ENTRY("THD_write_1D") ;
00234 
00235    if( !ISVALID_DSET(dset) || !DSET_LOADED(dset) ) EXRETURN ;
00236 
00237    nv = DSET_NVALS(dset) ;  /* number of columns */
00238    nx = DSET_NX(dset)    ;
00239    ny = DSET_NY(dset)    ;
00240    nz = DSET_NZ(dset)    ; nxyz = nx*ny*nz ;  /* number of rows */
00241 
00242    /* make up a filename for output (into fname) */
00243 
00244    cpt = DSET_PREFIX(dset) ;
00245    if( (pname != NULL && *pname == '-') ||
00246        (pname == NULL && *cpt   == '-')   ){  /* 12 Jul 2005: to stdout */
00247      fp = stdout ; strcpy(fname,"stdout") ; binflag = 0 ;
00248    }
00249 
00250    if( fp == NULL ){
00251      if( pname != NULL ){        /* have input prefix */
00252        if( sname != NULL ){      /* and input session (directory) */
00253          strcpy(fname,sname) ;
00254          ii = strlen(fname) ; if( fname[ii-1] != '/' ) strcat(fname,"/") ;
00255        } else {
00256          strcpy(fname,"./") ;    /* don't have input session */
00257        }
00258        strcat(fname,pname) ;
00259      } else {                    /* don't have input prefix */
00260        cpt = DSET_PREFIX(dset) ;
00261        if( STRING_HAS_SUFFIX(cpt,".3D") || STRING_HAS_SUFFIX(cpt,".1D") )
00262          strcpy(fname,cpt) ;
00263        else
00264          strcpy(fname,DSET_BRIKNAME(dset)) ;
00265 
00266        cpt = strchr(fname,'[') ;
00267        if( cpt != NULL ) *cpt = '\0' ;                  /* without subscripts! */
00268      }
00269      ii = strlen(fname) ;
00270      if( ii > 10 && strstr(fname,".BRIK") != NULL ){    /* delete .BRIK! */
00271        fname[ii-10] = '\0' ;
00272        if( DSET_IS_1D(dset) || (ny==1 && nz==1) )
00273          strcat(fname,".1D");
00274        else
00275          strcat(fname,".3D");                           /* 21 Mar 2003 */
00276      }
00277 
00278      fp = fopen( fname , "w" ) ; if( fp == NULL ) EXRETURN ;
00279      binflag = STRING_HAS_SUFFIX(fname,".3D") && AFNI_yesenv("AFNI_3D_BINARY") ;
00280    }
00281 
00282    strcpy( dset->dblk->diskptr->brick_name , fname ); /* 12 Jul 2005 */
00283 
00284    /* are we going to write in binary? [03 Jun 2005] */
00285 
00286    shp = (binflag) ? ' ' : '#' ;
00287 
00288    /* write some dataset info as NIML-style header/comments */
00289 
00290    if( fp != stdout )
00291      fprintf(fp,
00292                 "%c <AFNI_3D_dataset\n"
00293                 "%c  self_idcode = \"%s\"\n"
00294                 "%c  ni_type     = \"%d*float\"\n"    /* all columns are floats! */
00295                 "%c  ni_dimen    = \"%d,%d,%d\"\n"
00296                 "%c  ni_delta    = \"%g,%g,%g\"\n"
00297                 "%c  ni_origin   = \"%g,%g,%g\"\n"
00298                 "%c  ni_axes     = \"%s,%s,%s\"\n"
00299              ,
00300                 shp ,
00301                 shp , dset->idcode.str ,
00302                 shp , nv ,
00303                 shp , nx,ny,nz ,
00304                 shp , DSET_DX(dset)  , DSET_DY(dset)  , DSET_DZ(dset)  ,
00305                 shp , DSET_XORG(dset), DSET_YORG(dset), DSET_ZORG(dset),
00306                 shp , ORIENT_shortstr[dset->daxes->xxorient] ,
00307                        ORIENT_shortstr[dset->daxes->yyorient] ,
00308                          ORIENT_shortstr[dset->daxes->zzorient]
00309             ) ;
00310 
00311    if( fp != stdout && HAS_TIMEAXIS(dset) ){
00312      float dt = DSET_TR(dset) ;
00313      if( DSET_TIMEUNITS(dset) == UNITS_MSEC_TYPE ) dt *= 0.001 ;
00314      fprintf(fp , "%c  ni_timestep = \"%g\"\n" , shp,dt ) ;
00315    }
00316 
00317    if( fp != stdout && binflag )
00318      fprintf(fp , "   ni_form     = \"binary.%s\"\n" ,
00319                   (NI_byteorder()==NI_LSB_FIRST) ? "lsbfirst" : "msbfirst" ) ;
00320 
00321    /* do stataux for bricks, if any are present */
00322 
00323    for( ii=iv=0 ; iv < nv ; iv++ )
00324      if( DSET_BRICK_STATCODE(dset,iv) > 0 ) ii++ ;
00325 
00326    if( fp != stdout && ii > 0 ){
00327       fprintf(fp, "%c  ni_stat     = \"",shp) ;
00328       for( iv=0 ; iv < nv ; iv++ ){
00329         ii = DSET_BRICK_STATCODE(dset,iv) ;
00330         if( ii <=0 ){
00331           fprintf(fp,"none") ;
00332         } else {
00333           fprintf(fp,"%s(",NI_stat_distname(ii)) ;
00334           kk = NI_stat_numparam(ii) ;
00335           for( jj=0 ; jj < kk ; jj++ ){
00336             fprintf(fp,"%g",DSET_BRICK_STATPAR(dset,iv,jj)) ;
00337             if( jj < kk-1 ) fprintf(fp,",") ;
00338           }
00339           fprintf(fp,")") ;
00340         }
00341         if( ii < nv-1 ) fprintf(fp,";") ;
00342       }
00343       fprintf(fp,"\"\n") ;
00344    }
00345 
00346    /* close NIML-style header */
00347 
00348    if( fp != stdout ){
00349      if( binflag ) fprintf(fp," >") ;
00350      else          fprintf(fp,"# >\n") ;
00351      fflush(fp) ;
00352    }
00353 
00354    /* now write data */
00355 
00356    for( ii=0 ; ii < nxyz ; ii++ ){  /* loop over voxels */
00357 
00358      for( iv=0 ; iv < nv ; iv++ ){            /* loop over sub-bricks = columns */
00359        switch( DSET_BRICK_TYPE(dset,iv) ){
00360           default:
00361             val[0] = 0.0f ;
00362           break ;
00363 
00364           case MRI_float:{
00365             float *bar = DSET_ARRAY(dset,iv) ; val[0] = bar[ii] ;
00366           }
00367           break ;
00368 
00369           case MRI_short:{
00370             short *bar = DSET_ARRAY(dset,iv) ;
00371             float fac = DSET_BRICK_FACTOR(dset,iv) ; if( fac == 0.0 ) fac = 1.0 ;
00372             val[0] = fac*bar[ii] ;
00373           }
00374           break ;
00375 
00376           case MRI_byte:{
00377             byte *bar = DSET_ARRAY(dset,iv) ;
00378             float fac = DSET_BRICK_FACTOR(dset,iv) ; if( fac == 0.0 ) fac = 1.0 ;
00379             val[0] = fac*bar[ii] ;
00380           }
00381           break ;
00382 
00383           /* below here, we convert complicated types to floats, losing data! */
00384 
00385           case MRI_complex:{
00386             complex *bar = DSET_ARRAY(dset,iv) ;
00387             val[0] = CABS(bar[ii]) ;
00388           }
00389           break ;
00390 
00391           case MRI_rgb:{
00392             rgbyte *bar = DSET_ARRAY(dset,iv) ;
00393             val[0] = (0.299*bar[ii].r+0.587*bar[ii].g+0.114*bar[ii].g) ;
00394           }
00395           break ;
00396        } /* end of switch on sub-brick data type */
00397 
00398        if( binflag ) fwrite( val , sizeof(float) , 1 , fp ) ;
00399        else          fprintf( fp , " %g" , val[0] ) ;
00400 
00401      } /* end of loop over sub-bricks */
00402 
00403      if( !binflag ) fprintf(fp,"\n") ;
00404 
00405    } /* end of loop over voxels */
00406 
00407    /* NIML-style trailer */
00408 
00409    fflush(fp) ;
00410 
00411    if( fp != stdout ){
00412      fprintf(fp,"%c </AFNI_3D_dataset>\n",shp) ;
00413      fclose(fp) ;
00414    }
00415 
00416    EXRETURN ;
00417 }

void THD_write_3D char *    sname,
char *    pname,
THD_3dim_dataset   dset
 

Write a dataset to disk as a 3D file. Called from THD_write_3dim_dataset(). This is kind of cheating, since we just call THD_write_1D() instead. --------------------------------------------------------------------

Definition at line 324 of file thd_3Ddset.c.

References THD_write_1D().

Referenced by THD_write_3dim_dataset().

00325 {
00326    THD_write_1D( sname,pname,dset ) ;
00327 }

Boolean THD_write_3dim_dataset char *    new_sessname,
char *    new_prefixname,
THD_3dim_dataset   dset,
Boolean    write_brick
 

This routine writes all the header data in the struct to the datablock attributes, then writes the dataset to disk.

29 Apr 1998: erase attributes that are unused, so that they won't be left over from a previous life

09 Mar 2005: attributes are now set in function THD_set_dataset_attributes() rather than here

06 Apr 2005: might go all NIFTI on you ------------------------------------------------------------------

Definition at line 30 of file thd_writedset.c.

References THD_diskptr::brick_name, calloc, THD_3dim_dataset::dblk, niftiwr_opts_t::debug_level, THD_datablock::diskptr, DSET_DIRNAME, DSET_IS_1D, DSET_IS_3D, DSET_IS_ANALYZE, DSET_IS_CTFMRI, DSET_IS_CTFSAM, DSET_IS_MASTERED, DSET_IS_MINC, DSET_IS_TCAT, DSET_IS_VOLUMES, DSET_NY, DSET_NZ, DSET_PREFIX, ENTRY, free, niftiwr_opts_t::infile_name, ISVALID_3DIM_DATASET, ISVALID_DATABLOCK, ISVALID_DISKPTR, my_getenv(), THD_datablock::parent, RETURN, STRING_HAS_SUFFIX, THD_init_diskptr_names(), THD_set_dataset_attributes(), THD_write_1D(), THD_write_3D(), THD_write_datablock(), THD_write_nifti(), use_3D_format, use_NIFTI_format, and THD_3dim_dataset::view_type.

Referenced by adwarp_refashion_dataset(), AFNI_fimmer_execute(), AFNI_marks_action_CB(), AFNI_marks_transform_CB(), AFNI_refashion_dataset(), DUP_main(), IMREG_main(), main(), output_results(), output_ts_array(), PLUTO_add_dset(), RT_tell_afni_one(), RT_worker(), T3D_save_file_CB(), THD_3dim_from_block(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), and write_ts_array().

00032 {
00033    THD_datablock *blk ;
00034    int ii ;
00035    char *ppp ;  /* 06 Apr 2005 */
00036 
00037 ENTRY("THD_write_3dim_dataset") ;
00038 
00039    /*-- sanity checks --*/
00040 
00041    if( ! ISVALID_3DIM_DATASET(dset)    ||
00042        ! ISVALID_DATABLOCK(dset->dblk) ||
00043        ! ISVALID_DISKPTR(dset->dblk->diskptr) ) RETURN(False) ;
00044 
00045    blk = dset->dblk ;
00046    blk->parent = (XtPointer)dset ;  /* 05 Jul 2005 */
00047 
00048    /* Can only write AFNI formatted datasets */
00049 
00050    if( DSET_IS_MINC(dset)     ) RETURN(False) ;  /* 29 Oct 2001 */
00051    if( DSET_IS_MASTERED(dset) ) RETURN(False) ;  /* 11 Jan 1999 */
00052    if( DSET_IS_ANALYZE(dset)  ) RETURN(False) ;  /* 27 Aug 2002 */
00053    if( DSET_IS_CTFMRI(dset)   ) RETURN(False) ;  /* 05 Dec 2002 */
00054    if( DSET_IS_CTFSAM(dset)   ) RETURN(False) ;  /* 05 Dec 2002 */
00055    if( DSET_IS_TCAT(dset)     ) RETURN(False) ;  /* 05 Aug 2004 */
00056 
00057    if( DSET_IS_VOLUMES(dset) && write_brick ) RETURN(False) ;  /* 20 Jun 2002 */
00058 
00059    if( DSET_IS_1D(dset) ||
00060        ( DSET_NY(dset)==1 && DSET_NZ(dset)==1 ) ){            /* 04 Mar 2003 */
00061 
00062      THD_write_1D( new_sessname , new_prefixname , dset ) ;
00063      RETURN(True) ;
00064    }
00065 
00066    /*------------------------------*/
00067    /*-----  change filenames? -----*/
00068 
00069    THD_init_diskptr_names( blk->diskptr ,
00070                            new_sessname , NULL , new_prefixname ,
00071                            dset->view_type , True ) ;
00072 
00073    /*----- 09 Mar 2005: set attribute structs in the datablock -----*/
00074 
00075    THD_set_dataset_attributes( dset ) ;
00076 
00077    /*------ 06 Apr 2005: write a NIFTI-1 dataset??? -----*/
00078 
00079    ppp = DSET_PREFIX(dset) ;
00080    if( STRING_HAS_SUFFIX(ppp,".nii")    ||
00081        STRING_HAS_SUFFIX(ppp,".nii.gz") || use_NIFTI_format ){
00082 
00083      niftiwr_opts_t options ;
00084 
00085      ii = strlen(DSET_DIRNAME(dset)) + strlen(ppp) + 16 ;
00086      options.infile_name = calloc(1,ii) ;
00087      strcpy(options.infile_name,DSET_DIRNAME(dset)) ;
00088      strcat(options.infile_name,ppp) ;
00089 
00090      if( !STRING_HAS_SUFFIX(options.infile_name,".nii")    &&
00091          !STRING_HAS_SUFFIX(options.infile_name,".nii.gz")   )
00092        strcat(options.infile_name,".nii") ;
00093 
00094      {  /* set the nifti_io debug level       8 Apr 2005 [rickr] */
00095         char * ept = my_getenv("AFNI_NIFTI_DEBUG");
00096         if( ept != NULL ) options.debug_level = atoi(ept);
00097         else              options.debug_level = 0 ;
00098      }
00099 
00100      if( !write_brick ){
00101        fprintf(stderr,
00102                "** ERROR: can't write HEADER only for NIfTI-1 file: %s\n",
00103                options.infile_name ) ;
00104        ii = 0 ;
00105      } else {
00106        ii = THD_write_nifti(dset,options) ;
00107        strcpy( dset->dblk->diskptr->brick_name , options.infile_name ) ;
00108      }
00109 
00110      free((void *)options.infile_name) ;
00111      RETURN( (Boolean)ii ) ;
00112    }
00113 
00114    /*------ 21 Mar 2003: use the .3D format? -----*/
00115 
00116    if( STRING_HAS_SUFFIX(ppp,".3D") || DSET_IS_3D(dset) || use_3D_format ){
00117      if( !write_brick ){
00118        fprintf(stderr,
00119                "** ERROR: can't write HEADER only for .3D file: %s\n",
00120                DSET_PREFIX(dset) ) ;
00121        RETURN(False) ;
00122      }
00123      THD_write_3D( NULL, NULL, dset ) ; RETURN(True) ;
00124    }
00125 
00126    /*----- write datablock to disk in AFNI .HEAD/.BRIK format -----*/
00127 
00128    RETURN( THD_write_datablock(blk,write_brick) ) ;
00129 }

Boolean THD_write_atr THD_datablock  
 

Definition at line 12 of file thd_writeatr.c.

References AFNI_yesenv(), THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, DBLK_IS_ANALYZE, DBLK_IS_CTFMRI, DBLK_IS_CTFSAM, DBLK_IS_MINC, DBLK_IS_MPEG, DBLK_IS_NIFTI, THD_datablock::diskptr, ENTRY, FAIL, ATR_float::fl, THD_diskptr::header_name, ATR_int::in, ISVALID_DATABLOCK, ISVALID_DISKPTR, ATR_float::name, ATR_int::name, ATR_string::name, THD_datablock::natr, ATR_string::nch, ATR_float::nfl, ATR_int::nin, RETURN, SUCCESS, THD_unzblock(), THD_write_nimlatr(), THD_zblock(), and ATR_any::type.

Referenced by THD_write_datablock().

00013 {
00014    THD_diskptr *dkptr ;
00015    int ia , code , ii ;
00016    ATR_any *atr_any ;
00017    Boolean good = True ;
00018    FILE *header_file ;
00019 
00020 ENTRY("THD_write_atr") ;
00021 
00022    /*--- sanity checks ---*/
00023 
00024    if( ! ISVALID_DATABLOCK(blk) ) RETURN( False );
00025 
00026    dkptr = blk->diskptr ;
00027    if( ! ISVALID_DISKPTR(dkptr) || strlen(dkptr->header_name) == 0 ) RETURN( False );
00028 
00029    if( DBLK_IS_MINC(blk)    ) RETURN( False ); /* 29 Oct 2001 */
00030    if( DBLK_IS_ANALYZE(blk) ) RETURN( False ); /* 27 Aug 2002 */
00031    if( DBLK_IS_NIFTI(blk)   ) RETURN( False ); /* 28 Aug 2003 */
00032    if( DBLK_IS_CTFMRI(blk)  ) RETURN( False );
00033    if( DBLK_IS_CTFSAM(blk)  ) RETURN( False );
00034    if( DBLK_IS_MPEG(blk)    ) RETURN( False );
00035 
00036    /** 01 Jun 2005: perhaps write in the new NIML format? **/
00037 
00038    if( AFNI_yesenv("AFNI_WRITE_NIML") ){
00039      return THD_write_nimlatr( blk ) ;
00040    }
00041 
00042    /** Write the old AFNI format **/
00043 
00044    header_file = fopen( dkptr->header_name , "w" ) ;
00045    if( header_file == NULL ){
00046       fprintf(stderr,
00047               "*** ERROR: failed to open file %s for attribute writing;\n"
00048               "         - Do you have permission to write to this disk?\n"
00049               "         - Is the disk full?\n" ,
00050               dkptr->header_name) ;
00051       RETURN( False );
00052    }
00053 
00054    for( ia=0 ; ia < blk->natr ; ia++ ){
00055 
00056       atr_any = &(blk->atr[ia]) ;
00057       if( atr_any == NULL ) continue ;
00058 
00059       code = SUCCESS ;
00060       switch( atr_any->type ){
00061 
00062          case ATR_FLOAT_TYPE:{
00063             ATR_float * atr_flo = (ATR_float *) atr_any ;
00064 
00065             code = fprintf( header_file ,
00066                             "\ntype  = %s\nname  = %s\ncount = %d\n" ,
00067                             ATR_typestr[ATR_FLOAT_TYPE] ,
00068                             atr_flo->name , atr_flo->nfl ) ;
00069 
00070             if( code < 1 ){ code = FAIL ; break ; }
00071 
00072             for( ii=0 ; ii < atr_flo->nfl ; ii++ ){
00073                code = fprintf( header_file , " %14.7g" , atr_flo->fl[ii] ) ;
00074                if( ii % 5 == 4 && ii < atr_flo->nfl-1 )
00075                   fprintf( header_file , "\n" ) ;
00076             }
00077 
00078             code = (code < 1 ) ? FAIL : SUCCESS ;
00079          }
00080          break ;
00081 
00082          case ATR_INT_TYPE:{
00083             ATR_int * atr_int = (ATR_int *) atr_any ;
00084 
00085             code = fprintf( header_file ,
00086                             "\ntype = %s\nname = %s\ncount = %d\n" ,
00087                             ATR_typestr[ATR_INT_TYPE] ,
00088                             atr_int->name , atr_int->nin ) ;
00089 
00090             if( code < 1 ){ code = FAIL ; break ; }
00091 
00092             for( ii=0 ; ii < atr_int->nin ; ii++ ){
00093                code = fprintf( header_file , " %d" , atr_int->in[ii] ) ;
00094                if( ii % 5 == 4 && ii < atr_int->nin-1 )
00095                   fprintf( header_file , "\n" ) ;
00096             }
00097 
00098             code = (code < 1 ) ? FAIL : SUCCESS ;
00099          }
00100          break ;
00101 
00102          case ATR_STRING_TYPE:{
00103             ATR_string * atr_str = (ATR_string *) atr_any ;
00104 
00105             code = fprintf( header_file ,
00106                             "\ntype = %s\nname = %s\ncount = %d\n" ,
00107                             ATR_typestr[ATR_STRING_TYPE] ,
00108                             atr_str->name , atr_str->nch ) ;
00109 
00110 
00111             if( code < 1 ){ code = FAIL ; break ; }
00112 
00113             THD_zblock( atr_str->nch , atr_str->ch ) ;
00114 
00115             fprintf( header_file , "'" ) ;
00116             for( ii=0 ; ii < atr_str->nch ; ii++ ){
00117                code = fprintf( header_file , "%c" , atr_str->ch[ii] ) ;
00118             }
00119 
00120             code = (code < 1) ? FAIL : SUCCESS ;
00121 
00122             THD_unzblock( atr_str->nch , atr_str->ch ) ;
00123          }
00124          break ;
00125 
00126       } /* end of switch on atr type */
00127 
00128       good = good && (code != FAIL) ;  /* all must not FAIL */
00129       fprintf(header_file,"\n") ;
00130 
00131    } /* end of loop over all atr's */
00132 
00133    if( good == False ){
00134       fprintf(stderr,
00135               "*** WARNING: error in output to attribute file %s;\n"
00136               "           - Is the disk full?\n" ,
00137               dkptr->header_name) ;
00138    }
00139 
00140    /*--- close it down ---*/
00141 
00142    fclose( header_file ) ;
00143    RETURN( True );
00144 }

Boolean THD_write_datablock THD_datablock   blk,
Boolean    write_brick
 

Write an AFNI datablock to disk in the .HEAD/.BRIK format:

  • Returns True if OK, False if an error.
  • See also AFNI_refashion_dataset.
  • All attributes must now be set prior to calling this, via function THD_set_dataset_attributes().
  • The one exception to the above rule is the BYTEORDER attribute. -----------------------------------------------------------------------

Definition at line 99 of file thd_writedblk.c.

References AFNI_yesenv(), ATRNAME_BYTEORDER, ATRSIZE_DATASET_DIMENSIONS, ATRSIZE_DATASET_RANK, THD_datablock::brick, THD_diskptr::brick_name, THD_diskptr::byte_order, COMPRESS_fclose(), COMPRESS_fopen_write(), COMPRESS_GZIP, compress_mode, COMPRESS_NOFILE, COMPRESS_NONE, COMPRESS_unlink(), DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DATABLOCK_MEM_UNDEFINED, DATASET_BRICK_SUFFIX, DBLK_ARRAY, DBLK_BRICK, DBLK_BRICK_BYTES, DBLK_BRICK_NVOX, DBLK_BRICK_TYPE, DBLK_IS_ANALYZE, DBLK_IS_MASTERED, DBLK_IS_MINC, DBLK_IS_NIFTI, DBLK_mmapfix, THD_diskptr::dimsizes, THD_diskptr::directory_name, THD_datablock::diskptr, ENTROPY_datablock(), far, THD_diskptr::filecode, free, THD_diskptr::header_name, ISVALID_DATABLOCK, ISVALID_DISKPTR, LSB_FIRST_STRING, malloc, THD_datablock::malloc_type, mri_clear_data_pointer, mri_fix_data_pointer(), mri_short_order(), mri_swap2(), mri_swap4(), MSB_FIRST_STRING, native_order, THD_datablock::nvals, THD_diskptr::nvals, nz, offset, output_order, THD_diskptr::rank, STORAGE_BY_BRICK, STORAGE_BY_VOLUMES, THD_diskptr::storage_mode, STORAGE_UNDEFINED, THD_count_databricks(), THD_enviro_write_compression(), THD_enviro_write_order(), THD_is_directory(), THD_MKDIR_MODE, THD_purge_datablock(), THD_set_string_atr, THD_write_atr(), THD_datablock::total_bytes, and WRITE_ERR.

Referenced by THD_write_3dim_dataset().

00100 {
00101    THD_diskptr *dkptr ;
00102    Boolean good ;
00103    int id , nx , ny , nz , nv , nxy , nxyz , ibr ;
00104    int atrank[ATRSIZE_DATASET_RANK] , atdims[ATRSIZE_DATASET_DIMENSIONS] ;
00105    MRI_IMAGE *im ;
00106    int save_order ;
00107    int64_t nb , idone ;
00108 
00109    /*-- sanity checks --*/
00110 
00111    if( ! ISVALID_DATABLOCK(blk) ) return False ;
00112    if( DBLK_IS_MASTERED(blk) )    return False ;  /* 11 Jan 1999 */
00113    if( DBLK_IS_MINC(blk) )        return False ;  /* 29 Oct 2001 */
00114    if( DBLK_IS_ANALYZE(blk) )     return False ;  /* 27 Aug 2002 */
00115    if( DBLK_IS_NIFTI(blk) )       return False ;  /* 28 Aug 2003 */
00116 
00117    dkptr = blk->diskptr ;
00118    if( ! ISVALID_DISKPTR(dkptr) ) WRITE_ERR("illegal file type") ;
00119 
00120    if( strlen(dkptr->directory_name) == 0 ||
00121        strlen(dkptr->header_name)    == 0 ||
00122        strlen(dkptr->filecode)       == 0   )
00123      WRITE_ERR("illegal file names stored in dataset") ;
00124 
00125    if( dkptr->rank != 3 )
00126       WRITE_ERR("cannot write non-3D datablock") ;
00127 
00128    /*-- create directory if necessary --*/
00129 
00130    if( ! THD_is_directory(dkptr->directory_name) ){
00131       id = mkdir( dkptr->directory_name , THD_MKDIR_MODE ) ;
00132       if( id != 0 ){
00133          fprintf(stderr,
00134               "\n"
00135               "*** cannot mkdir new directory: %s\n"
00136               "  - Do you have permission to write to this disk?\n"
00137               "  - Is the disk full?\n" ,
00138               dkptr->directory_name) ;
00139          return False ;
00140       }
00141    }
00142 
00143    /* 25 April 1998: deal with byte order issues */
00144 
00145    if( native_order < 0 ){                /* initialization */
00146       native_order = mri_short_order() ;
00147       if( output_order < 0 ) THD_enviro_write_order() ;
00148    }
00149    if( dkptr->byte_order <= 0 ) dkptr->byte_order = native_order ;
00150    save_order = (output_order > 0) ? output_order
00151                                    : dkptr->byte_order ;
00152 
00153 #if 0
00154 fprintf(stderr,"THD_write_datablock: save_order=%d  dkptr->byte_order=%d\n",
00155                save_order, dkptr->byte_order ) ;
00156 #endif
00157 
00158    if( save_order != LSB_FIRST && save_order != MSB_FIRST )
00159      save_order = native_order ;
00160 
00161    if( save_order == LSB_FIRST )
00162      THD_set_string_atr( blk , ATRNAME_BYTEORDER , LSB_FIRST_STRING ) ;
00163    else if( save_order == MSB_FIRST )
00164      THD_set_string_atr( blk , ATRNAME_BYTEORDER , MSB_FIRST_STRING ) ;
00165 
00166    /*-- actually write attributes to disk --*/
00167 
00168    good = THD_write_atr( blk ) ;
00169    if( good == False )
00170      WRITE_ERR("failure to write attributes - is disk full? do you have write permission?") ;
00171 
00172    /*-- if not writing data, can exit --*/
00173 
00174    if( write_brick == False || blk->brick == NULL ||
00175        dkptr->storage_mode == STORAGE_UNDEFINED     ) return True ;
00176 
00177    if( dkptr->storage_mode == STORAGE_BY_VOLUMES ){  /* 20 Jun 2002 */
00178      fprintf(stderr,"** Writing dataset by VOLUMES not yet supported.\n") ;
00179      return False ;
00180    }
00181 
00182    /*-- check each brick for existence:
00183           if none exist, cannot write, but is OK
00184           if some but not all exist, cannot write, and is an error --*/
00185 
00186    id = THD_count_databricks( blk ) ;
00187    if( id <= 0 )         return True ;
00188    if( id < blk->nvals ) WRITE_ERR("only partial data exists in memory") ;
00189 
00190    if( blk->malloc_type == DATABLOCK_MEM_UNDEFINED )
00191       WRITE_ERR("undefined data exists in memory") ;
00192 
00193    /*-- write data out in whatever format is ordered --*/
00194 
00195    nx = dkptr->dimsizes[0] ;
00196    ny = dkptr->dimsizes[1] ;  nxy  = nx * ny ;
00197    nz = dkptr->dimsizes[2] ;  nxyz = nxy * nz ;
00198    nv = dkptr->nvals ;        nb   = blk->total_bytes ;
00199 
00200    switch( dkptr->storage_mode ){
00201 
00202       default: WRITE_ERR("illegal storage_mode!") ; break ;
00203 
00204       case STORAGE_BY_BRICK:{
00205          FILE *far ;
00206          Boolean purge_when_done = False , ok ;
00207          int force_gzip=0 , csave ;
00208 
00209          /** if we have a mmap-ed file, copy into RAM (ugh) **/
00210 
00211          if( blk->malloc_type == DATABLOCK_MEM_MMAP ){
00212             char *bnew , *bold ;
00213             int offset ;
00214 
00215             bnew = (char *) malloc( (size_t)nb ) ;  /* work space */
00216             bold = DBLK_ARRAY(blk,0) ;              /* start of mapped file */
00217 
00218             if( bnew == NULL )
00219               WRITE_ERR("cannot rewrite due to malloc failure - is memory exhausted?") ;
00220 
00221             memcpy( bnew , bold , (size_t)nb ) ;    /* make a copy,    */
00222             munmap( (void *) bold , (size_t)nb ) ;  /* then unmap file */
00223 
00224             /* fix sub-brick pointers */
00225 
00226             offset = 0 ;
00227             for( ibr=0 ; ibr < nv ; ibr++ ){
00228                mri_fix_data_pointer( (void *)(bnew+offset) , DBLK_BRICK(blk,ibr) ) ;
00229                offset += DBLK_BRICK_BYTES(blk,ibr) ;
00230             }
00231 
00232             purge_when_done = True ;
00233          }
00234 
00235          if( save_order != native_order ) purge_when_done = True ;
00236 
00237          /** delete old file, if any **/
00238 
00239          COMPRESS_unlink( dkptr->brick_name ) ; /* Feb 1998 */
00240 
00241          /** create new file **/
00242 
00243          id = strlen(dkptr->directory_name) ;
00244          ok = ( dkptr->directory_name[id-1] == '/' ) ;
00245          if( ok ) sprintf( dkptr->brick_name , "%s%s.%s",
00246                            dkptr->directory_name ,
00247                            dkptr->filecode , DATASET_BRICK_SUFFIX );
00248 
00249          else     sprintf( dkptr->brick_name , "%s/%s.%s",
00250                            dkptr->directory_name ,
00251                            dkptr->filecode , DATASET_BRICK_SUFFIX );
00252 
00253       /** COMPRESS for output added Feb 1998 */
00254 
00255          if( compress_mode == COMPRESS_NOFILE ) THD_enviro_write_compression() ;
00256 
00257 #ifdef COMPRESS_GZIP
00258          /*-- 02 Mar 2001: check if we will force gzip --*/
00259 
00260          if( compress_mode == COMPRESS_NONE && AFNI_yesenv("AFNI_AUTOGZIP") ){
00261             double entrop = ENTROPY_datablock(blk) ;
00262             force_gzip = (entrop < 2.7) ;
00263 #if 0
00264 fprintf(stderr,"Entropy=%g ==> forcing write gzip on %s\n",entrop,dkptr->brick_name) ;
00265 #endif
00266          } else {
00267             force_gzip = 0 ;
00268          }
00269          if( force_gzip ){
00270             csave = compress_mode ; compress_mode = COMPRESS_GZIP ;
00271          }
00272 #endif
00273 
00274          far = COMPRESS_fopen_write( dkptr->brick_name , compress_mode ) ;
00275          if( far == NULL )
00276            WRITE_ERR("cannot open output brick file - do you have write permission?") ;
00277 
00278          /** write each brick out in a separate operation **/
00279 
00280          idone = 0 ;
00281          for( ibr=0 ; ibr < nv ; ibr++ ){
00282 
00283            if( save_order != native_order ){       /* 25 April 1998 */
00284              switch( DBLK_BRICK_TYPE(blk,ibr) ){
00285                case MRI_short:
00286                  mri_swap2( DBLK_BRICK_NVOX(blk,ibr) , DBLK_ARRAY(blk,ibr) ) ;
00287                break ;
00288 
00289                case MRI_complex:   /* 23 Nov 1999 */
00290                  mri_swap4( 2*DBLK_BRICK_NVOX(blk,ibr), DBLK_ARRAY(blk,ibr)) ;
00291                break ;
00292 
00293                case MRI_float:     /* 23 Nov 1999 */
00294                case MRI_int:
00295                  mri_swap4( DBLK_BRICK_NVOX(blk,ibr) , DBLK_ARRAY(blk,ibr) ) ;
00296                break ;
00297              }
00298            }
00299 
00300            idone += fwrite( DBLK_ARRAY(blk,ibr), 1, DBLK_BRICK_BYTES(blk,ibr), far );
00301          }
00302 
00303          COMPRESS_fclose(far) ;
00304 
00305          if( purge_when_done ){
00306            if( blk->malloc_type == DATABLOCK_MEM_MMAP ){
00307              free( DBLK_ARRAY(blk,0) ) ;
00308              for( ibr=0 ; ibr < nv ; ibr++ )
00309                mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00310            } else {
00311              THD_purge_datablock( blk , DATABLOCK_MEM_MALLOC ) ;
00312            }
00313          }
00314 
00315          if( compress_mode >= 0 || save_order != native_order ){
00316            blk->malloc_type = DATABLOCK_MEM_MALLOC ;
00317          }
00318          DBLK_mmapfix(blk) ;  /* 28 Mar 2005 */
00319 
00320          if( force_gzip ) compress_mode = csave ; /* 02 Mar 2001 */
00321 
00322          if( idone != blk->total_bytes )
00323            WRITE_ERR("Write error in brick file: Is disk full, or write_protected?") ;
00324 
00325          dkptr->byte_order = save_order ;  /* 23 Nov 1999 */
00326 
00327          return True ;
00328       }
00329       break ;
00330 
00331    }  /* end of switch over data storage mode */
00332 
00333    return False ;  /* should NEVER be reached */
00334 }

int THD_write_minc char *    fname,
THD_3dim_dataset   dset,
int    flags
 

Write an AFNI dataset as a MINC file.

  • fname = MINC filename
  • dset = AFNI dataset
  • flags = logical OR of various masks:
  • MINC_FLOATIZE_MASK => force output in float format
Return value is 1 if went OK, 0 if not. -------------------------------------------------------------------

Definition at line 14 of file thd_mincwrite.c.

References AFMALL, THD_3dim_dataset::daxes, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_LOADED, DSET_NUM_TIMES, DSET_NVALS, DSET_NVOX, DSET_TIMESTEP, DSET_unload_one, EDIT_coerce_scale_type(), ENTRY, far, flags, free, ISVALID_DSET, malloc, MINC_FLOATIZE_MASK, mri_datum_size(), THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, pclose, popen, RETURN, THD_filename_ok(), THD_find_executable(), VIEW_TALAIRACH_TYPE, THD_3dim_dataset::view_type, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::yyorient, THD_dataxes::zzdel, THD_dataxes::zzorg, and THD_dataxes::zzorient.

Referenced by main().

00015 {
00016    static char *pg=NULL ; static int first=1 ;
00017 
00018    int nvals,nvox , iv , floatize , ii , datum , good=1 ;
00019    THD_dataxes *dax ;
00020    char  axcode[3] ;
00021    float axstep[3] , axstart[3] ;
00022    int   axnum[3] ;
00023    char *cmd ;
00024    FILE *fp ;
00025    void *bar ;
00026    float *far=NULL ;
00027 
00028 ENTRY("THD_write_minc") ;
00029 
00030    /*-- check inputs for goodness --*/
00031 
00032    if( !THD_filename_ok(fname) || fname[0] == '-' ){
00033       fprintf(stderr,"** ERROR: Illegal filename for MINC output: %s\n",
00034               (fname != NULL) ? fname : "(null)" ) ;
00035       RETURN(0) ;
00036    }
00037 
00038    if( !ISVALID_DSET(dset) ){
00039       fprintf(stderr,
00040               "** ERROR: Illegal input dataset for MINC output: %s\n",
00041               fname ) ;
00042       RETURN(0) ;
00043    }
00044 
00045    /*-- find rawtominc program to do the real work --*/
00046 
00047    if( first ){
00048      pg = THD_find_executable("rawtominc") ; first = 0 ;
00049    }
00050 
00051    if( pg == NULL ){
00052      fprintf(stderr,
00053              "** ERROR: Can't write MINC file without program rawtominc: %s\n",
00054              fname);
00055      RETURN(0) ;
00056    }
00057 
00058    /*-- load dataset from disk, if need be --*/
00059 
00060    DSET_load(dset) ;
00061    if( !DSET_LOADED(dset) ){
00062      fprintf(stderr,
00063              "** ERROR: Can't write MINC file since dataset isn't loaded: %s\n",
00064              fname) ;
00065      RETURN(0) ;
00066    }
00067 
00068    /*-- check sub-bricks for uniformity in type, legal type, etc. --*/
00069 
00070    nvals    = DSET_NVALS(dset) ;
00071    nvox     = DSET_NVOX(dset) ;
00072    floatize = (flags & MINC_FLOATIZE_MASK) != 0 ;
00073    ii       = DSET_BRICK_TYPE(dset,0) ;
00074 
00075    for( iv=0 ; iv < nvals ; iv++ ){
00076      if( DSET_BRICK_TYPE(dset,iv) == MRI_complex ){
00077        fprintf(stderr,
00078                "** ERROR: Can't write MINC file since dataset is complex: %s\n",
00079                fname) ;
00080        RETURN(0) ;
00081      }
00082      if( DSET_BRICK_TYPE(dset,iv) == MRI_rgb ){
00083        fprintf(stderr,
00084                "** ERROR: Can't write MINC file since dataset is RGB: %s\n",
00085                fname) ;
00086        RETURN(0) ;
00087      }
00088 
00089      /* check if must convert to floats */
00090 
00091      if( !floatize ){
00092         if( DSET_BRICK_TYPE(dset,iv)   == MRI_float ||
00093             DSET_BRICK_FACTOR(dset,iv) != 0.0       ||
00094             DSET_BRICK_TYPE(dset,iv)   != ii          ){
00095 
00096           floatize = 1 ;
00097           fprintf(stderr,
00098                   "++ NOTE: Writing MINC file in float format: %s\n",
00099                   fname) ;
00100         }
00101      }
00102    }
00103 
00104    if( floatize ) datum = MRI_float ;
00105    else           datum = ii ;
00106 
00107    /*-- load geometry information --*/
00108 
00109    dax = dset->daxes ;
00110 
00111    axcode[0] = ORIENT_xyz[ dax->xxorient ] ; axnum[0] = dax->nxx ;
00112    axcode[1] = ORIENT_xyz[ dax->yyorient ] ; axnum[1] = dax->nyy ;
00113    axcode[2] = ORIENT_xyz[ dax->zzorient ] ; axnum[2] = dax->nzz ;
00114 
00115    axstep[0] = dax->xxdel ; axstart[0] = dax->xxorg ;
00116    axstep[1] = dax->yydel ; axstart[1] = dax->yyorg ;
00117    axstep[2] = dax->zzdel ; axstart[2] = dax->zzorg ;
00118 
00119    if( axcode[0] == 'x' || axcode[0] == 'y' ){
00120      axstep[0] = -axstep[0] ; axstart[0] = -axstart[0] ;
00121    }
00122 
00123    if( axcode[1] == 'x' || axcode[1] == 'y' ){
00124      axstep[1] = -axstep[1] ; axstart[1] = -axstart[1] ;
00125    }
00126 
00127    if( axcode[2] == 'x' || axcode[2] == 'y' ){
00128      axstep[2] = -axstep[2] ; axstart[2] = -axstart[2] ;
00129    }
00130 
00131    /*-- start to create command --*/
00132 
00133    cmd = AFMALL(char, 65500) ; /* long enough?  */
00134    strcpy(cmd,pg) ;      /* basic command */
00135 
00136    /* axes orientation */
00137 
00138    sprintf(cmd+strlen(cmd)," -%c%c%c",axcode[2],axcode[1],axcode[0]) ;
00139 
00140    /* input and output data type */
00141 
00142    sprintf(cmd+strlen(cmd)," -%s -o%s",
00143            MRI_TYPE_name[datum],MRI_TYPE_name[datum]) ;
00144 
00145    /* axis stuff */
00146 
00147    sprintf(cmd+strlen(cmd),
00148            " -%cstep %.3f -%cstep %.3f -%cstep %.3f"
00149            " -%cstart %.3f -%cstart %.3f -%cstart %.3f"
00150            " -xdircos 1 0 0 -ydircos 0 1 0 -zdircos 0 0 1" ,
00151            axcode[0],axstep[0] ,axcode[1],axstep[1] ,axcode[2],axstep[2]  ,
00152            axcode[0],axstart[0],axcode[1],axstart[1],axcode[2],axstart[2]  ) ;
00153 
00154    /*-- do we create a time step attribute? --*/
00155 
00156    if( nvals > 1 & DSET_NUM_TIMES(dset) > 1 && DSET_TIMESTEP(dset) > 0.0 ){
00157      float tr = DSET_TIMESTEP(dset) ;
00158      sprintf(cmd+strlen(cmd)," -dattribute time:step=%.3f",tr) ;
00159      sprintf(cmd+strlen(cmd)," -frame_times '") ;
00160      for( iv=0 ; iv < nvals ; iv++ )
00161        sprintf(cmd+strlen(cmd),"%.3f ",iv*tr) ;
00162      strcat(cmd,"'") ;
00163    }
00164 
00165    /*-- Is this Talaraich? --*/
00166 
00167    if( dset->view_type == VIEW_TALAIRACH_TYPE ){
00168      sprintf(cmd+strlen(cmd)," -sattribute xspace:spacetype=talairach_") ;
00169      sprintf(cmd+strlen(cmd)," -sattribute yspace:spacetype=talairach_") ;
00170      sprintf(cmd+strlen(cmd)," -sattribute zspace:spacetype=talairach_") ;
00171    }
00172 
00173    /*-- integer datasets need to be scanned    --*/
00174    /*-- and have valid_range set (stupid MINC) --*/
00175 
00176    if( !floatize ){
00177      sprintf(cmd+strlen(cmd)," -scan_range") ;
00178      switch( datum ){
00179         case MRI_short:
00180           sprintf(cmd+strlen(cmd)," -range 0 32767") ; break ;
00181 
00182         case MRI_byte:
00183           sprintf(cmd+strlen(cmd)," -range 0 255")   ; break ;
00184      }
00185    }
00186 
00187    /*-- add output file name --*/
00188 
00189    sprintf(cmd+strlen(cmd)," %s",fname) ;
00190 
00191    /*-- add # sub-bricks, if > 1 --*/
00192 
00193    if( nvals > 1 ) sprintf(cmd+strlen(cmd)," %d",nvals) ;
00194 
00195    /*-- add number of points along each axis --*/
00196 
00197    sprintf(cmd+strlen(cmd)," %d %d %d" , axnum[2],axnum[1],axnum[0] ) ;
00198 
00199    /*-- execute the command as a filter --*/
00200 
00201    signal( SIGPIPE , SIG_IGN ) ; errno = 0 ;
00202    fp = popen( cmd , "w" ) ;
00203    if( fp == NULL ){
00204      fprintf(stderr,"** ERROR: Can't open MINC output filter: %s\a\n",cmd) ;
00205      if( errno != 0 ) perror("** Unix error message") ;
00206      free(cmd) ; RETURN(0) ;
00207    }
00208 
00209    /*-- allocate space for floatizing --*/
00210 
00211    if( floatize ){
00212      far = (float *) malloc(sizeof(float)*nvox) ;
00213      if( far == NULL ){
00214        fprintf(stderr,
00215                "** ERROR: Can't write MINC file due to lack of memory: %s\n",
00216                fname) ;
00217        free(cmd) ; RETURN(0) ;
00218      }
00219    }
00220 
00221    /*-- loop through sub-bricks, convert to floats if needed, write to pipe --*/
00222 
00223    for( iv=0 ; iv < nvals ; iv++ ){
00224       bar = DSET_ARRAY(dset,iv) ; errno = 0 ;
00225       if( floatize ){
00226         EDIT_coerce_scale_type( nvox ,
00227                                 DSET_BRICK_FACTOR(dset,iv) ,
00228                                 DSET_BRICK_TYPE(dset,iv)   , bar ,
00229                                 MRI_float                  , far  ) ;
00230         ii = fwrite( far , sizeof(float)         , nvox , fp ) ;
00231       } else {
00232         ii = fwrite( bar , mri_datum_size(datum) , nvox , fp ) ;
00233       }
00234 
00235       DSET_unload_one(dset,iv) ;
00236 
00237       if( ii < nvox ){
00238         fprintf(stderr,
00239                 "** ERROR: fwrite to MINC failed at iv=%d: %s\n",
00240                 iv , fname ) ;
00241         if( errno ) perror("fwrite") ;
00242         if( ii == 0 ){ good=0; break; }       /* don't try to continue */
00243       }
00244    }
00245 
00246    if( floatize ) free(far) ;  /* no longer needed */
00247 
00248    /*-- close pipe --*/
00249 
00250    ii = pclose(fp) ;
00251    if( ii == -1 ){
00252      perror("** ERROR in MINC write filter") ;
00253      fprintf(stderr,"** MINC filter command was %s\n\a",cmd) ;
00254      free(cmd) ; RETURN(0) ;
00255    }
00256 
00257    /*-- and we are done --*/
00258 
00259    free(cmd) ; RETURN(good) ;
00260 }

Boolean THD_write_nimlatr THD_datablock   blk
 

Write the old AFNI format *

Definition at line 148 of file thd_writeatr.c.

References THD_datablock::diskptr, ENTRY, THD_diskptr::header_name, ISVALID_DSET, NI_set_attribute(), NI_stream_close(), NI_stream_open(), NI_stream_writestring(), NI_TEXT_MODE, NI_write_element(), THD_datablock::parent, THD_diskptr::prefix, RETURN, STATUS, and THD_nimlize_dsetatr().

Referenced by THD_write_atr().

00149 {
00150    NI_stream ns ;
00151    NI_group  *ngr ;
00152    char sname[2048] ;
00153    THD_3dim_dataset *dset ;
00154 
00155 ENTRY("THD_write_nimlatr") ;
00156 
00157    /* get dataset that contains this datablock */
00158 
00159    dset = (THD_3dim_dataset *)blk->parent ;
00160    if( !ISVALID_DSET(dset) ){
00161      STATUS("parent is not valid dataset!"); RETURN(False);      /* bad */
00162    }
00163 
00164    /* convert dataset struct AFNI attributes into a NIML element */
00165 
00166    ngr = THD_nimlize_dsetatr( dset ) ;
00167    if( ngr == NULL ){
00168      STATUS("can't create NIML header element!"); RETURN(False); /* bad */
00169    }
00170    NI_set_attribute( ngr , "self_prefix" , blk->diskptr->prefix ) ;
00171 
00172    /* open output NIML stream (to file) */
00173 
00174    sprintf(sname,"file:%s",blk->diskptr->header_name) ;
00175    ns = NI_stream_open( sname , "w" ) ;
00176    if( ns == (NI_stream)NULL ){
00177      STATUS("can't open output NIML stream!"); RETURN(False);    /* bad */
00178    }
00179 
00180    /* write XML header and then the AFNI header element */
00181 
00182    STATUS("writing NIML header") ;
00183    NI_stream_writestring( ns , "<?xml version='1.0' ?>\n" ) ;
00184    NI_write_element( ns , ngr , NI_TEXT_MODE ) ;
00185    NI_stream_close( ns ) ;
00186    RETURN(True) ;
00187 }

void THD_zblock int   ,
char *   
 

Definition at line 15 of file thd_zblock.c.

References ZBLOCK.

Referenced by THD_nimlize_dsetatr(), and THD_write_atr().

00016 {
00017    int ii ;
00018    if( nch <= 0 ) return ;
00019 
00020    for( ii=0 ; ii < nch ; ii++ ){
00021      if( ch[ii] == ZBLOCK ) ch[ii] = '*' ;  /* irreversible */
00022      if( ch[ii] == '\0'   ) ch[ii] = ZBLOCK ;
00023    }
00024 }

void THD_zerofill_dataset THD_3dim_dataset   dset
 

Fill up a dataset with zero-ed out sub-bricks, if needed. ------------------------------------------------------------------------------

Definition at line 965 of file thd_loaddblk.c.

References calloc, THD_3dim_dataset::dblk, DSET_ARRAY, DSET_BRICK, DSET_BRICK_BYTES, DSET_NVALS, ENTRY, ISVALID_DATABLOCK, ISVALID_DSET, and mri_fix_data_pointer().

Referenced by THD_niml_to_dataset().

00966 {
00967    int ii ;
00968    void *vpt ;
00969 
00970 ENTRY("THD_zerofill_dataset") ;
00971 
00972    if( !ISVALID_DSET(dset) || !ISVALID_DATABLOCK(dset->dblk) ) EXRETURN ;
00973 
00974    for( ii=0 ; ii < DSET_NVALS(dset) ; ii++ ){
00975      if( DSET_ARRAY(dset,ii) == NULL ){
00976        vpt = calloc(1,DSET_BRICK_BYTES(dset,ii)) ;
00977        mri_fix_data_pointer( vpt , DSET_BRICK(dset,ii) ) ;
00978      }
00979    }
00980    EXRETURN ;
00981 }

THD_3dim_dataset* THD_zeropad THD_3dim_dataset  ,
int   ,
int   ,
int   ,
int   ,
int   ,
int   ,
char *   ,
int   
 

Definition at line 18 of file thd_zeropad.c.

References ADN_none, ADN_nsl, ADN_nxyz, ADN_prefix, ADN_toff_sl, ADN_xyzorg, ADN_zorg_sl, THD_3dim_dataset::anat_parent_name, calloc, THD_3dim_dataset::daxes, DSET_BRICK, DSET_delete, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_unload, DSET_unload_one, EDIT_dset_items(), EDIT_empty_copy(), EDIT_full_copy(), EDIT_substitute_brick(), EDIT_ZERO_ANATOMY_PARENT_ID, ENTRY, free, ISVALID_DSET, MRI_IMAGE::kind, LOAD_FVEC3, LOAD_IVEC3, malloc, MAX, MIN, mri_data_pointer(), THD_timeaxis::nsl, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, MRI_IMAGE::pixel_size, RETURN, STATUS, THD_3dim_dataset::taxis, THD_filename_ok(), THD_timeaxis::toff_sl, THD_dataxes::xxdel, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_dataxes::yydel, THD_dataxes::yyorg, THD_dataxes::yyorient, THD_timeaxis::zorg_sl, ZPAD_EMPTY, ZPAD_MM, ZPAD_PURGE, THD_dataxes::zzdel, THD_dataxes::zzorg, and THD_dataxes::zzorient.

Referenced by main(), T3D_save_file_CB(), THD_warp3D(), TT_retrieve_atlas_big(), and ZPAD_main().

00022 {
00023    THD_3dim_dataset *outset ;
00024    int nxold,nyold,nzold , nxnew,nynew,nznew , nxyold,nxynew ,
00025        nxbot=0,nxtop=0 , nybot=0,nytop=0 , nzbot=0,nztop=0    ;
00026    int ii,jj,kk , iv , iibot,iitop , jjbot,jjtop , kkbot,kktop ;
00027 
00028    int empty_flag = (flag & ZPAD_EMPTY) ;  /* 09 Feb 2001 */
00029    int purge_flag = (flag & ZPAD_PURGE) ;  /* 09 Feb 2001 */
00030    int mm_flag    = (flag & ZPAD_MM   ) ;  /* 13 Feb 2001 */
00031 
00032    THD_ivec3 iv_nxyz ;
00033    THD_fvec3 fv_xyzorg ;
00034 
00035    MRI_IMAGE * oldim ;
00036    void * vnew ;
00037 
00038 ENTRY("THD_zeropad") ;
00039 
00040    /*-- check inputs --*/
00041 
00042    if( !ISVALID_DSET(inset) ) RETURN( NULL ) ;
00043 
00044    if( add_I==0 && add_S==0 && add_P==0 &&
00045        add_A==0 && add_L==0 && add_R==0    ){
00046 
00047       fprintf(stderr,"++ THD_zeropad: all pad values are zero!\n") ;
00048 
00049       outset = EDIT_full_copy( inset , prefix ) ;  /* 14 May 2002 */
00050       RETURN( outset );
00051    }
00052 
00053    if( !THD_filename_ok(prefix) ) prefix = "zeropad" ;
00054 
00055    /*-- map add_? values into dataset xyz coordinate directions --*/
00056 
00057    nxold = DSET_NX(inset) ;
00058    nyold = DSET_NY(inset) ;
00059    nzold = DSET_NZ(inset) ;
00060 
00061    /* comput n?top and n?bot, the number of planes to add at
00062       the top and bottom of the ? direction, for ? = x, y, or z */
00063 
00064    switch( inset->daxes->xxorient ){
00065       default:
00066         fprintf(stderr,"*** THD_zeropad: Unknown orientation codes!\n") ;
00067         RETURN( NULL );
00068 
00069       case ORI_R2L_TYPE: nxtop = add_L ; nxbot = add_R ; break ;
00070       case ORI_L2R_TYPE: nxtop = add_R ; nxbot = add_L ; break ;
00071       case ORI_P2A_TYPE: nxtop = add_A ; nxbot = add_P ; break ;
00072       case ORI_A2P_TYPE: nxtop = add_P ; nxbot = add_A ; break ;
00073       case ORI_I2S_TYPE: nxtop = add_S ; nxbot = add_I ; break ;
00074       case ORI_S2I_TYPE: nxtop = add_I ; nxbot = add_S ; break ;
00075    }
00076 
00077    switch( inset->daxes->yyorient ){
00078       default:
00079         fprintf(stderr,"*** THD_zeropad: Unknown orientation codes!\n") ;
00080         RETURN( NULL );
00081 
00082       case ORI_R2L_TYPE: nytop = add_L ; nybot = add_R ; break ;
00083       case ORI_L2R_TYPE: nytop = add_R ; nybot = add_L ; break ;
00084       case ORI_P2A_TYPE: nytop = add_A ; nybot = add_P ; break ;
00085       case ORI_A2P_TYPE: nytop = add_P ; nybot = add_A ; break ;
00086       case ORI_I2S_TYPE: nytop = add_S ; nybot = add_I ; break ;
00087       case ORI_S2I_TYPE: nytop = add_I ; nybot = add_S ; break ;
00088    }
00089 
00090    switch( inset->daxes->zzorient ){
00091       default:
00092         fprintf(stderr,"*** THD_zeropad: Unknown orientation codes!\n") ;
00093         RETURN( NULL );
00094 
00095       case ORI_R2L_TYPE: nztop = add_L ; nzbot = add_R ; break ;
00096       case ORI_L2R_TYPE: nztop = add_R ; nzbot = add_L ; break ;
00097       case ORI_P2A_TYPE: nztop = add_A ; nzbot = add_P ; break ;
00098       case ORI_A2P_TYPE: nztop = add_P ; nzbot = add_A ; break ;
00099       case ORI_I2S_TYPE: nztop = add_S ; nzbot = add_I ; break ;
00100       case ORI_S2I_TYPE: nztop = add_I ; nzbot = add_S ; break ;
00101    }
00102 
00103    /* 13 Feb 2001: round to millimeters? */
00104 
00105 #undef  RMM
00106 #define RMM(n,d)                                                           \
00107   do{      if( (n) > 0 ) (n) = (int)( (n)/fabs(d) + 0.999 ) ;              \
00108       else if( (n) < 0 ) (n) = (int)( (n)/fabs(d) - 0.999 ) ; } while(0) ;
00109 
00110    if( mm_flag ){
00111       RMM(nxtop,inset->daxes->xxdel) ; RMM(nxbot,inset->daxes->xxdel) ;
00112       RMM(nytop,inset->daxes->yydel) ; RMM(nybot,inset->daxes->yydel) ;
00113       RMM(nztop,inset->daxes->zzdel) ; RMM(nzbot,inset->daxes->zzdel) ;
00114    }
00115 
00116    nxnew = nxold + nxbot + nxtop ;  /* dimensions of new bricks */
00117    nynew = nyold + nybot + nytop ;
00118    nznew = nzold + nzbot + nztop ;
00119 
00120    nxyold = nxold * nyold ;         /* for computing subscripts */
00121    nxynew = nxnew * nynew ;
00122 
00123    iibot = MAX(0,-nxbot) ; iitop = MIN(nxold,nxold+nxtop) ;  /* range of data */
00124    jjbot = MAX(0,-nybot) ; jjtop = MIN(nyold,nyold+nytop) ;  /* in old dataset */
00125    kkbot = MAX(0,-nzbot) ; kktop = MIN(nzold,nzold+nztop) ;
00126 
00127    if( nxnew < 1 || iibot > iitop ||   /* check for reasonable sizes */
00128        nynew < 1 || jjbot > jjtop ||   /* and ranges of dataset     */
00129        nznew < 1 || kkbot > kktop   ){
00130 
00131       fprintf(stderr,"*** THD_zeropad: Can't cut dataset down too much!\n") ;
00132       RETURN( NULL );
00133    }
00134 
00135 #if 0
00136    if( nxnew < 2 || iibot >= iitop ||   /* check for reasonable sizes */
00137        nynew < 2 || jjbot >= jjtop ||   /* and ranges of dataset     */
00138        nznew < 2 || kkbot >= kktop   ){
00139 
00140       fprintf(stderr,"*** WARNING - THD_zeropad: dataset cut down to %dx%dx%d\n",
00141                       nxnew,nynew,nznew) ;
00142    }
00143 #endif
00144 
00145    /*-- create the shell of the new dataset --*/
00146 
00147    outset = EDIT_empty_copy( inset ) ;
00148 
00149    LOAD_IVEC3( iv_nxyz , nxnew,nynew,nznew ) ;
00150 
00151    LOAD_FVEC3( fv_xyzorg, inset->daxes->xxorg - nxbot * inset->daxes->xxdel,
00152                           inset->daxes->yyorg - nybot * inset->daxes->yydel,
00153                           inset->daxes->zzorg - nzbot * inset->daxes->zzdel );
00154 
00155 STATUS("setting new dimensions") ;
00156 
00157    EDIT_dset_items( outset ,
00158                        ADN_prefix , prefix    ,
00159                        ADN_nxyz   , iv_nxyz   ,
00160                        ADN_xyzorg , fv_xyzorg ,
00161                     ADN_none ) ;
00162 
00163    /* Changing dimensions means old anat parent is no longer valid! */
00164 
00165    EDIT_ZERO_ANATOMY_PARENT_ID( outset ) ;
00166    outset->anat_parent_name[0] = '\0' ;
00167 
00168 #if 0
00169    /* if changing number of slices, can't keep slice-dependent time shifts! */
00170 
00171    if( (nzbot!=0 || nztop!=0) && outset->taxis != NULL && outset->taxis->nsl > 0 ){
00172       EDIT_dset_items( outset , ADN_nsl , 0 , ADN_none ) ;
00173       fprintf(stderr,
00174               "*** THD_zeropad: warning - slice-dependent time shifts have been removed!\n") ;
00175    }
00176 #else
00177    /* 31 Jan 2001: OK, lets keeps the slice-dependent time shifts
00178                    (but we'll have to mangle them) -- RWCox      */
00179 
00180    if( (nzbot!=0 || nztop!=0) && outset->taxis != NULL && outset->taxis->nsl > 0 ){
00181       int old_nsl , new_nsl , ii, nkeep,kbot,ibot ;
00182       float old_zorg_sl , *old_toff_sl , new_zorg_sl , *new_toff_sl ;
00183 
00184       /* copy current conditions to local variables */
00185 
00186       old_nsl     = outset->taxis->nsl ;
00187       old_zorg_sl = outset->taxis->zorg_sl ;
00188       old_toff_sl = (float *) malloc(sizeof(float)*old_nsl) ;
00189       memcpy( old_toff_sl , outset->taxis->toff_sl , sizeof(float)*old_nsl ) ;
00190 
00191       /* compute new values */
00192 
00193       new_nsl     = nznew ;
00194       new_zorg_sl = outset->daxes->zzorg ;                      /* cf. to3d.c */
00195       new_toff_sl = (float *) malloc(sizeof(float)*new_nsl) ;
00196       for( ii=0 ; ii < new_nsl ; ii++ ) new_toff_sl[ii] = 0.0 ; /* extras are 0 */
00197 
00198       nkeep = old_nsl ;                 /* how many to keep from the old list */
00199       if( nzbot < 0 ) nkeep += nzbot ;  /* lost this many at the bottom */
00200       if( nztop < 0 ) nkeep += nztop ;  /* lost this many at the top */
00201 
00202       if( nzbot < 0 ){
00203          kbot = -nzbot ;   /* which old one to start with */
00204          ibot = 0 ;        /* and where it goes in new list */
00205       } else {
00206          kbot = 0 ;
00207          ibot = nzbot ;
00208       }
00209 
00210       memcpy( new_toff_sl+ibot , old_toff_sl+kbot , sizeof(float)*nkeep ) ;
00211 
00212       /* set new values in dataset */
00213 
00214 STATUS("setting new time-offsets") ;
00215 
00216       EDIT_dset_items( outset ,
00217                          ADN_nsl     , new_nsl     ,
00218                          ADN_toff_sl , new_toff_sl ,
00219                          ADN_zorg_sl , new_zorg_sl ,
00220                        ADN_none ) ;
00221 
00222       free(new_toff_sl) ; free(old_toff_sl) ;
00223    }
00224 #endif
00225 
00226    if( empty_flag ) RETURN(outset) ;  /* 09 Feb 2001 */
00227 
00228    /*-- now read the old dataset in, and make bricks for the new dataset --*/
00229 
00230 STATUS("reading dataset in") ;
00231 
00232    DSET_load(inset) ;
00233    if( !DSET_LOADED(inset) ){
00234       fprintf(stderr,"*** THD_zeropad: Can't load input dataset BRIK!\n");
00235       DSET_delete(outset) ;
00236       RETURN( NULL );
00237    }
00238 
00239 STATUS("padding") ;
00240 
00241    for( iv=0 ; iv < DSET_NVALS(inset) ; iv++ ){
00242 
00243       /* create a brick of zeros */
00244 
00245       oldim = DSET_BRICK(inset,iv) ;  /* image structure of old brick */
00246 
00247       vnew  = (void*)calloc( nxnew*nynew*nznew , 
00248                              oldim->pixel_size ) ; /* new brick */
00249       if( vnew == NULL ){
00250          fprintf(stderr,
00251                  "*** THD_zeropad: Can't malloc space for new sub-brick %d\n",
00252                  iv) ;
00253          DSET_delete(outset) ; RETURN( NULL );
00254       }
00255 
00256       /* macros for computing 1D subscripts from 3D indices */
00257 
00258 #undef  SNEW  /* in case was defined in some stupid .h file */
00259 #undef  SOLD
00260 #define SNEW(i,j,k) ((i+nxbot)+(j+nybot)*nxnew+(k+nzbot)*nxynew)
00261 #define SOLD(i,j,k) (i+j*nxold+k*nxyold)
00262 
00263       switch( oldim->kind ){  /* copy rows of old into new */
00264 
00265          case MRI_byte:{
00266             byte * bnew = (byte *) vnew, * bold = mri_data_pointer(oldim) ;
00267             for( kk=kkbot ; kk < kktop ; kk++ )
00268                for( jj=jjbot ; jj < jjtop ; jj++ )
00269                   for( ii=iibot ; ii < iitop ; ii++ )
00270                      bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ;
00271          }
00272          break ;
00273 
00274          case MRI_short:{
00275             short * bnew = (short *) vnew, * bold = mri_data_pointer(oldim) ;
00276             for( kk=kkbot ; kk < kktop ; kk++ )
00277                for( jj=jjbot ; jj < jjtop ; jj++ )
00278                   for( ii=iibot ; ii < iitop ; ii++ )
00279                      bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ;
00280          }
00281          break ;
00282 
00283          case MRI_float:{
00284             float * bnew = (float *) vnew, * bold = mri_data_pointer(oldim) ;
00285             for( kk=kkbot ; kk < kktop ; kk++ )
00286                for( jj=jjbot ; jj < jjtop ; jj++ )
00287                   for( ii=iibot ; ii < iitop ; ii++ )
00288                      bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ;
00289          }
00290          break ;
00291 
00292          case MRI_complex:{
00293             complex * bnew = (complex *) vnew, * bold = mri_data_pointer(oldim) ;
00294             for( kk=kkbot ; kk < kktop ; kk++ )
00295                for( jj=jjbot ; jj < jjtop ; jj++ )
00296                   for( ii=iibot ; ii < iitop ; ii++ )
00297                      bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ;
00298          }
00299          break ;
00300 
00301          case MRI_int:{
00302             int * bnew = (int *) vnew, * bold = mri_data_pointer(oldim) ;
00303             for( kk=kkbot ; kk < kktop ; kk++ )
00304                for( jj=jjbot ; jj < jjtop ; jj++ )
00305                   for( ii=iibot ; ii < iitop ; ii++ )
00306                      bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ;
00307          }
00308          break ;
00309 
00310          case MRI_rgb:{
00311             rgbyte * bnew = (rgbyte *) vnew, * bold = mri_data_pointer(oldim) ;
00312             for( kk=kkbot ; kk < kktop ; kk++ )
00313                for( jj=jjbot ; jj < jjtop ; jj++ )
00314                   for( ii=iibot ; ii < iitop ; ii++ )
00315                      bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ;
00316          }
00317          break ;
00318 
00319       } /* end of switch on sub-brick type */
00320 
00321       if( purge_flag) DSET_unload_one(inset,iv) ; /* 09 Feb 2001 */
00322 
00323       EDIT_substitute_brick( outset , iv , oldim->kind , vnew ) ;
00324 
00325    } /* end of loop on sub-brick index */
00326 
00327 #if 0
00328    if( purge_flag ) DSET_unload(inset) ; /* 09 Feb 2001 */
00329 #endif
00330 
00331    RETURN( outset );
00332 }

char * THD_zzprintf char *    sss,
char *    fmt,
...   
 

If present, print out Notes *

Definition at line 361 of file thd_info.c.

00362 {
00363    static char *sbuf = NULL ;
00364    char *zz ;
00365    int   nzz , nsbuf ;
00366    va_list vararg_ptr ;
00367 
00368    va_start( vararg_ptr , fmt ) ;
00369 
00370    if( sbuf == NULL ) sbuf = AFMALL(char, ZMAX+90) ;
00371 
00372    sbuf[0] = '\0' ;
00373    vsprintf( sbuf , fmt , vararg_ptr ) ;
00374    nsbuf = strlen(sbuf) ;
00375    if( nsbuf == 0 ) return sss ;
00376 
00377    if( sss == NULL ){
00378       zz = (char *) malloc( sizeof(char)*(nsbuf+2) ) ;
00379       strcpy(zz,sbuf) ;
00380    } else {
00381       nzz = strlen(sss) + nsbuf + 2 ;
00382       zz  = (char *) malloc( sizeof(char) * nzz ) ;
00383       strcpy(zz,sss) ; strcat(zz,sbuf) ;
00384       free(sss) ;
00385    }
00386    return zz ;
00387 }

void tross_Add_Note THD_3dim_dataset   dset,
char *    cn
 

Add a note after the last current note -----------------------------------------------------------------------------

Definition at line 103 of file thd_notes.c.

References THD_3dim_dataset::dblk, free, ATR_int::in, ISVALID_DSET, MAX_DSET_NOTES, THD_find_int_atr(), THD_set_int_atr(), THD_set_string_atr, tross_datetime(), and tross_Encode_String().

Referenced by main(), NOTES_add_CB(), RT_start_dataset(), and tross_Store_Note().

00104 {
00105    ATR_int *notecount;
00106    int num_notes;
00107    char note_name[20], *ch ;
00108 
00109    if( !ISVALID_DSET(dset) || cn == NULL || cn[0] == '\0' ) return ;
00110 
00111    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00112    if (notecount == NULL) {
00113       num_notes = 1;
00114       THD_set_int_atr(dset->dblk, "NOTES_COUNT", 1, &num_notes);
00115    } else {
00116       num_notes = notecount->in[0] + 1;
00117       if( num_notes > MAX_DSET_NOTES ){
00118          fprintf(stderr,"*** attempt to add too many notes to dataset!\n") ;
00119          return ;
00120       }
00121       notecount->in[0]++;
00122    }
00123 
00124    sprintf(note_name, "NOTE_NUMBER_%03d", num_notes);
00125    ch = tross_Encode_String(cn) ; if( ch == NULL ) return ;
00126    THD_set_string_atr(dset->dblk, note_name, ch);
00127    free(ch) ;
00128 
00129    ch = tross_datetime() ;
00130    sprintf(note_name, "NOTE_DATE_%03d", num_notes) ;
00131    THD_set_string_atr(dset->dblk, note_name, ch);
00132    free(ch);
00133 
00134    return ;
00135 }

void tross_Addto_History THD_3dim_dataset   old_dset,
THD_3dim_dataset   new_dset
 

Add the History in old_dset to that in new_dset [27 Feb 2003] -----------------------------------------------------------------------------

Definition at line 295 of file thd_notes.c.

References free, ISVALID_DSET, tross_Append_History(), and tross_Get_History().

Referenced by main().

00296 {
00297    char *ch ;
00298 
00299    if( !ISVALID_DSET(old_dset) || !ISVALID_DSET(new_dset) ) return ;
00300 
00301    ch = tross_Get_History( old_dset ) ; if( ch == NULL ) return ;
00302    tross_Append_History( new_dset , ch ) ; free(ch) ; return ;
00303 }

void tross_Append_History THD_3dim_dataset   dset,
char *    cn
 

Append a string to the dataset history (create the history if need be). -----------------------------------------------------------------------------

Definition at line 325 of file thd_notes.c.

References AFMALL, AFREALL, ATR_string::ch, THD_3dim_dataset::dblk, free, ISVALID_DSET, THD_find_string_atr(), THD_set_string_atr, tross_datetime(), tross_Encode_String(), tross_Expand_String(), tross_hostname(), and tross_username().

Referenced by AFNI_fimmer_execute(), AFNI_marks_action_CB(), AFNI_marks_transform_CB(), AFNI_refashion_dataset(), basis_write_iresp(), basis_write_sresp(), COPY_main(), DRAW_copy_dset(), DUP_main(), EDIT_main(), form_clusters(), IMREG_main(), main(), NUD_doall_CB(), output_ts_array(), POWER_main(), PRIC_main(), process_dataset(), REORDER_main(), RT_fim_recurse(), RT_start_dataset(), STAVG_main(), T3D_read_images(), T3D_save_file_CB(), THD_open_minc(), tross_Addto_History(), tross_Make_History(), tross_multi_Append_History(), VOLREG_main(), write_3dtime(), write_afni_data(), write_bucket(), write_bucket_data(), write_results(), and write_ts_array().

00326 {
00327    ATR_string * hist ;
00328    char * ch , * chold , * cdate , * cname , * cuser ;
00329    int idate , iname , iuser ;
00330 
00331    if( !ISVALID_DSET(dset) || cn == NULL || cn[0] == '\0' ) return ;
00332 
00333    hist = THD_find_string_atr(dset->dblk,"HISTORY_NOTE") ;
00334    cdate = tross_datetime() ; idate = strlen(cdate) ;
00335    cname = tross_hostname() ; iname = strlen(cname) ;  /* 19 Sep 1999 */
00336    cuser = tross_username() ; iuser = strlen(cuser) ;  /* 19 Sep 1999 */
00337 
00338    /*- add to the history -*/
00339 
00340    if( hist != NULL ){
00341 
00342       chold = tross_Expand_String(hist->ch) ; if( chold == NULL ) return ;
00343       chold = AFREALL( chold, char, 
00344                        strlen(chold)+idate+iuser+iname+strlen(cn)+12 ) ;
00345 
00346       strcat(chold,"\n") ;
00347       strcat(chold,"[") ; strcat(chold,cuser) ; strcat(chold,"@") ;
00348                           strcat(chold,cname) ; strcat(chold,": ") ;
00349                           strcat(chold,cdate) ;
00350       strcat(chold,"] ") ;
00351       strcat(chold,cn) ;
00352       ch = tross_Encode_String(chold) ; if( ch == NULL ){ free(chold); return; }
00353       THD_set_string_atr(dset->dblk, "HISTORY_NOTE", ch);
00354       free(ch) ; free(chold) ;
00355 
00356    /*- create the history -*/
00357 
00358    } else {
00359       chold = AFMALL(char, idate+iuser+iname+strlen(cn)+12 ) ;
00360       sprintf(chold,"[%s@%s: %s] %s",cuser,cname,cdate,cn) ;
00361       ch = tross_Encode_String(chold) ; if( ch == NULL ){ free(chold); return; }
00362       THD_set_string_atr(dset->dblk, "HISTORY_NOTE", ch);
00363       free(ch) ; free(chold) ;
00364    }
00365 
00366    free(cdate) ; free(cname) ; free(cuser) ; return ;
00367 }

char* tross_breakup_string char *    str,
int    lbot,
int    ltop
 

Break a string up into lines of length between lbot and ltop bytes; free() the result when done with it. NULL return means illegal input was found. -------------------------------------------------------------------------

Definition at line 468 of file thd_notes.c.

References AFMALL.

Referenced by NOTES_finalize_dset_CB().

00469 {
00470    char * sout ;
00471    int slen , ii , ibot,itop , ldif ;
00472 
00473    if( str == NULL || str[0] == '\0' || lbot > ltop || lbot < 4 ) return NULL ;
00474 
00475    slen = strlen(str) ; sout = AFMALL(char, slen+4) ;
00476 
00477    while( slen > lbot && isspace(str[slen-1]) ) slen-- ;  /* trim blanks off end */
00478 
00479    ibot = 0 ; ldif = ltop-lbot ;
00480    while(1){
00481       itop = ibot + ltop-1 ;    /* want to output str[ibot..itop] */
00482 
00483       /* if past end of str, then just output the rest and exit */
00484 
00485       if( itop >= slen ){
00486          memcpy( sout+ibot , str+ibot , slen-ibot ) ;
00487          sout[slen] = '\0' ;
00488          return sout ;
00489       }
00490 
00491       /* scan forwards to find a newline character before itop; */
00492       /* if one is present, output the string up to there,     */
00493       /* and continue again starting after the newline        */
00494 
00495       for( ii=ibot ; ii <= itop ; ii++ )
00496          if( str[ii] == '\n' ) break ;
00497 
00498       if( ii <= itop ){  /* found it! */
00499          memcpy( sout+ibot , str+ibot , ii-ibot+1 ) ;
00500          ibot = ii+1 ;
00501          if( ibot >= slen ){ sout[slen] = '\0'; return sout; }
00502          continue ;
00503       }
00504 
00505       /* scan backwards to find a whitespace character */
00506 
00507       for( ii=itop ; ii > itop-ldif ; ii-- )
00508          if( isspace(str[ii]) ) break ;
00509 
00510       /* found one before the minimum location      */
00511       /* copy up to the previous char into output, */
00512       /* then put a newline in for the whitespace */
00513 
00514       if( ii > itop-ldif ){
00515          memcpy( sout+ibot , str+ibot , ii-ibot ) ;
00516          sout[ii] = '\n' ;
00517          ibot = ii+1 ;
00518          continue ;         /* try to do next line */
00519       }
00520 
00521       /* scan ahead to next whitespace instead */
00522 
00523       for( ii=itop ; ii < slen ; ii++ )
00524          if( isspace(str[ii]) ) break ;
00525 
00526       /* found one */
00527 
00528       if( ii < slen ){
00529          memcpy( sout+ibot , str+ibot , ii-ibot ) ;
00530          sout[ii] = '\n' ;
00531          ibot = ii+1 ;
00532          continue ;
00533       }
00534 
00535       /* copy rest of input and exit */
00536 
00537       memcpy( sout+ibot , str+ibot , slen-ibot ) ;
00538       sout[slen] = '\0' ;
00539       return sout ;
00540    }
00541 }

char* tross_commandline char *    pname,
int    argc,
char **    argv
 

Assemble a sort-of command line string from the arguments; free() this when done. -----------------------------------------------------------------------------

Definition at line 25 of file thd_notes.c.

References AFMALL, AFREALL, argc, free, and THD_filename_ok().

Referenced by AFNI_logger(), basis_write_iresp(), basis_write_sresp(), initialize(), initialize_program(), T3D_initialize_user_data(), tross_Make_History(), and write_ts_array().

00026 {
00027    char * ch ;
00028    int ii , ll ;
00029 
00030    if( argc < 2 || argv == NULL ) return NULL ;
00031 
00032    if( pname == NULL ) pname = argv[0] ;
00033 
00034    ii = strlen(pname) ; ch = AFMALL(char, ii+4) ; strcpy(ch,pname) ;
00035 
00036    for( ii=1 ; ii < argc ; ii++ ){
00037       if( argv[ii] == NULL || argv[ii][0] == '\0' ) continue ; /* skip */
00038 
00039       ll = strlen(argv[ii]) ;
00040       ch = AFREALL(ch ,char, strlen(ch)+ll+4 ) ;  /* expand output array */
00041 
00042       if( !THD_filename_ok(argv[ii]) ){       /* bad characters? */
00043          int jj ; char * aa = AFMALL(char, ll+1) ;
00044 
00045          strcpy(aa,argv[ii]) ;        /* edit out bad characters */
00046          for( jj=0 ; jj < ll ; jj++ )
00047             if( iscntrl(aa[jj]) ||
00048                 isspace(aa[jj]) || (aa[jj] & 128) != 0 ) aa[jj] = ' ' ;
00049 
00050          strcat(ch," '") ; strcat(ch,aa) ; strcat(ch,"'") ; free(aa) ;
00051 
00052       } else {
00053          strcat(ch," ")  ; strcat(ch,argv[ii]) ;   /* just copy it */
00054       }
00055    }
00056 
00057    return ch ;
00058 }

void tross_Copy_History THD_3dim_dataset   old_dset,
THD_3dim_dataset   new_dset
 

Replace the History in new_dset with that from old_dset -----------------------------------------------------------------------------

Definition at line 279 of file thd_notes.c.

References THD_3dim_dataset::dblk, free, ISVALID_DSET, THD_set_string_atr, tross_Encode_String(), and tross_Get_History().

Referenced by AFNI_fimmer_execute(), AFNI_follower_dataset(), AFNI_marks_transform_CB(), applyMask(), basis_write_iresp(), basis_write_sresp(), COPY_main(), DRAW_copy_dset(), DUP_main(), EDIT_main(), form_clusters(), IMREG_main(), main(), POWER_main(), PRIC_main(), process_dataset(), REORDER_main(), STAVG_main(), VOLREG_main(), write_3dtime(), write_afni_data(), write_bucket(), write_bucket_data(), write_output(), write_results(), and write_ts_array().

00280 {
00281    char * ch , * cn ;
00282 
00283    if( !ISVALID_DSET(old_dset) || !ISVALID_DSET(new_dset) ) return ;
00284 
00285    ch = tross_Get_History( old_dset ) ;      if( ch == NULL ) return ;
00286    cn = tross_Encode_String(ch) ; free(ch) ; if( cn == NULL ) return;
00287    THD_set_string_atr(new_dset->dblk, "HISTORY_NOTE", cn);
00288    free(cn) ; return ;
00289 }

char* tross_datetime void   
 

Get the current date/time string; free() this when done. -----------------------------------------------------------------------------

Definition at line 64 of file thd_notes.c.

References AFMALL, i, and qh.

Referenced by AFNI_logger(), tross_Add_Note(), tross_Append_History(), tross_Store_Note(), and XSAVE_output().

00065 {
00066    time_t tnow = time(NULL) ; int i ; char * qh , * ch ;
00067 
00068    ch=ctime(&tnow); i=strlen(ch); qh=AFMALL(char, i+2); 
00069    strcpy(qh,ch); qh[i-1]='\0';
00070    return qh ;
00071 }

void tross_Delete_Note THD_3dim_dataset   dset,
int    inote
 

Delete a particular note -----------------------------------------------------------------------------

Definition at line 141 of file thd_notes.c.

References THD_3dim_dataset::dblk, ATR_int::in, ISVALID_DSET, MAX_DSET_NOTES, ATR_string::name, THD_erase_one_atr(), THD_find_int_atr(), and THD_find_string_atr().

Referenced by main(), and NOTES_delete_CB().

00142 {
00143    ATR_int *notecount;
00144    int num_notes;
00145    ATR_string *note_text;
00146    char note_name[20];
00147 
00148    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ) return ;
00149 
00150    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00151    if (notecount == NULL) return ;
00152 
00153    num_notes = notecount->in[0];
00154    if (inote > num_notes) return ;
00155 
00156    sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00157    note_text = THD_find_string_atr(dset->dblk, note_name);
00158    if( note_text == NULL ) return ;
00159    THD_erase_one_atr( dset->dblk , note_name );
00160 
00161    sprintf(note_name, "NOTE_DATE_%03d", inote);
00162    note_text = THD_find_string_atr(dset->dblk, note_name);
00163    if( note_text != NULL ) THD_erase_one_atr( dset->dblk , note_name );
00164 
00165    notecount->in[0]-- ;  /* where the note count is reduced */
00166 
00167    /* Slide the higher numbered notes down */
00168 
00169    while (inote < num_notes) {
00170       /* find the next note */
00171       sprintf(note_name, "NOTE_NUMBER_%03d", inote+1);
00172       note_text=THD_find_string_atr(dset->dblk, note_name);
00173       if (note_text != NULL){
00174          /* rename to the previous name */
00175          sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00176          strcpy(note_text->name, note_name);
00177       }
00178 
00179       sprintf(note_name,"NOTE_DATE_%03d",inote+1) ;
00180       note_text = THD_find_string_atr(dset->dblk, note_name);
00181       if (note_text != NULL){
00182          /* rename to the previous name */
00183          sprintf(note_name, "NOTE_DATE_%03d", inote);
00184          strcpy(note_text->name, note_name);
00185       }
00186 
00187       inote++ ;
00188    }
00189 
00190    /* No notes left, so remove count attribute */
00191    if (num_notes == 1)
00192       THD_erase_one_atr( dset->dblk, "NOTES_COUNT");
00193    return ;
00194 }

void tross_Dont_Encode_Slash int   
 

Definition at line 581 of file thd_notes.c.

References Dont_Encode_Slash, and q.

Referenced by main().

00581 { Dont_Encode_Slash = q ; return ; }

char* tross_Encode_String char *    cn
 

Reverse of tross_Expand_String ----------------------------------------------------------------------------

Definition at line 587 of file thd_notes.c.

References Dont_Encode_Slash, i, and malloc.

Referenced by tross_Add_Note(), tross_Append_History(), tross_Copy_History(), tross_Replace_History(), and tross_Store_Note().

00588 {
00589    char * ch = NULL ;
00590    int i , j , num_char ;
00591 
00592    if( cn == NULL || cn[0] == '\0' ) return NULL ;
00593 
00594    num_char = strlen(cn) ;
00595    ch = (char *) malloc( sizeof(char) * (2*num_char+4) ) ;
00596    for( i=j=0 ; j < num_char ; j++ ){
00597       switch( cn[j] ){
00598          default:   ch[i++] = cn[j]                ; break ;
00599          case '\r': ch[i++] = '\\' ; ch[i++] = 'r' ; break ;
00600          case '\n': ch[i++] = '\\' ; ch[i++] = 'n' ; break ;
00601          case '\"': ch[i++] = '\\' ; ch[i++] = '\"'; break ;
00602          case '\t': ch[i++] = '\\' ; ch[i++] = 't' ; break ;
00603          case '\a': ch[i++] = '\\' ; ch[i++] = 'a' ; break ;
00604          case '\v': ch[i++] = '\\' ; ch[i++] = 'v' ; break ;
00605          case '\b': ch[i++] = '\\' ; ch[i++] = 'b' ; break ;
00606 
00607          case '\\':                          ch[i++] = '\\';
00608                     if( !Dont_Encode_Slash ) ch[i++] = '\\';
00609          break ;
00610       }
00611    }
00612    ch[i] = '\0' ;
00613    for( i-- ; i > 0 ; i-- ) if( isspace(ch[i]) ) ch[i] = '\0' ; else break ;
00614    return ch ;
00615 }

char* tross_Expand_String char *    ch
 

Return a printable version of a note string; free() this when done -------------------------------------------------------------------------

Definition at line 547 of file thd_notes.c.

References i, and malloc.

Referenced by atr_print(), tross_Append_History(), tross_Get_History(), tross_Get_Note(), and tross_Get_Notedate().

00548 {
00549    char * cn = NULL ;
00550    int i, j, num_char;
00551 
00552    if( ch == NULL || ch[0] == '\0' ) return NULL ;
00553 
00554    num_char = strlen(ch) ;
00555    cn = (char *) malloc( sizeof(char) * (num_char+4) ) ;
00556    for( i=j=0 ; j < num_char ; j++ ){
00557       if( ch[j] != '\\' ){
00558          cn[i++] = ch[j] ;
00559       } else {
00560          switch (ch[++j] ){
00561             case 'r'  : cn[i++] = '\r' ; break;
00562             case 'n'  : cn[i++] = '\n' ; break;
00563             case '\\' : cn[i++] = '\\' ; break;
00564             case '"'  : cn[i++] = '\"' ; break;
00565             case 't'  : cn[i++] = '\t' ; break;
00566             case 'a'  : cn[i++] = '\a' ; break;
00567             case 'v'  : cn[i++] = '\v' ; break;
00568             case 'b'  : cn[i++] = '\b' ; break;
00569             default:    cn[i++] = '\\' ;         /* 13 Mar 2003 */
00570                         cn[i++] = ch[j]; break;
00571          }
00572       }
00573    }
00574    cn[i] = '\0' ; return cn ;
00575 }

char* tross_Get_History THD_3dim_dataset   dset
 

Get the history string; free() this when done. If NULL is returned, there is no history (cf. Santayana). ------------------------------------------------------------------------------

Definition at line 415 of file thd_notes.c.

References ATR_string::ch, THD_3dim_dataset::dblk, ISVALID_DSET, THD_find_string_atr(), and tross_Expand_String().

Referenced by NOTES_finalize_dset_CB(), THD_dataset_info(), tross_Addto_History(), and tross_Copy_History().

00416 {
00417    ATR_string * hist ;
00418    char * ch ;
00419 
00420    if( !ISVALID_DSET(dset) ) return NULL ;
00421 
00422    hist = THD_find_string_atr(dset->dblk,"HISTORY_NOTE") ;
00423    if( hist == NULL ) return NULL ;
00424 
00425    ch = tross_Expand_String(hist->ch) ; return ch ;
00426 }

char* tross_Get_Note THD_3dim_dataset   dset,
int    inote
 

Get the inote-th Note attached to the dataset. free() this string when done with it - it is a copy -----------------------------------------------------------------------------

Definition at line 217 of file thd_notes.c.

References ATR_string::ch, THD_3dim_dataset::dblk, ATR_int::in, ISVALID_DSET, MAX_DSET_NOTES, THD_find_int_atr(), THD_find_string_atr(), and tross_Expand_String().

Referenced by Display_Notes(), NOTES_add_CB(), NOTES_finalize_dset_CB(), and THD_dataset_info().

00218 {
00219    ATR_int *notecount;
00220    int num_notes;
00221    ATR_string *note ;
00222    char note_name[20], * ch ;
00223 
00224    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ) return NULL ;
00225 
00226    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00227    if (notecount == NULL) return NULL ;
00228    num_notes = notecount->in[0];
00229    if( inote > num_notes ) return NULL ;
00230 
00231    sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00232    note = THD_find_string_atr(dset->dblk, note_name);
00233    if (note == NULL ) return NULL ;
00234    ch = tross_Expand_String( note->ch ) ;
00235    return ch ;
00236 }

int tross_Get_Notecount THD_3dim_dataset   dset
 

Get the number of Notes currently attached to the dataset. Doesn't include the History note. -----------------------------------------------------------------------------

Definition at line 201 of file thd_notes.c.

References THD_3dim_dataset::dblk, ATR_int::in, ISVALID_DSET, and THD_find_int_atr().

Referenced by NOTES_finalize_dset_CB().

00202 {
00203    ATR_int *notecount;
00204 
00205    if( !ISVALID_DSET(dset) ) return -1 ;
00206 
00207    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00208    if (notecount == NULL) return 0 ;
00209    return notecount->in[0];
00210 }

char* tross_Get_Notedate THD_3dim_dataset  ,
int   
 

Definition at line 240 of file thd_notes.c.

References ATR_string::ch, THD_3dim_dataset::dblk, ATR_int::in, ISVALID_DSET, MAX_DSET_NOTES, THD_find_int_atr(), THD_find_string_atr(), and tross_Expand_String().

Referenced by Display_Notes(), NOTES_add_CB(), NOTES_finalize_dset_CB(), NOTES_save_CB(), and THD_dataset_info().

00241 {
00242    ATR_int *notecount;
00243    int num_notes;
00244    ATR_string *note ;
00245    char note_name[20];
00246 
00247    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ) return NULL ;
00248 
00249    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00250    if (notecount == NULL) return NULL ;
00251    num_notes = notecount->in[0];
00252    if( inote > num_notes ) return NULL ;
00253 
00254    sprintf(note_name, "NOTE_DATE_%03d", inote);
00255    note = THD_find_string_atr(dset->dblk, note_name);
00256    if (note == NULL ) return NULL ;
00257    return tross_Expand_String( note->ch ) ;
00258 }

char* tross_hostname void   
 

Definition at line 77 of file thd_notes.c.

References AFMALL, and NNAME.

Referenced by tross_Append_History(), and XSAVE_output().

00078 {
00079    char * cn = AFMALL(char, NNAME) ;
00080    gethostname( cn , NNAME ) ;
00081    return cn ;
00082 }

void tross_Make_History char *    pname,
int    argc,
char **    argv,
THD_3dim_dataset   dset
 

Add the history from the command line to the dataset. -----------------------------------------------------------------------------

Definition at line 264 of file thd_notes.c.

References argc, free, ISVALID_DSET, tross_Append_History(), and tross_commandline().

Referenced by applyMask(), do_xrestore_stuff(), main(), write_afni_fict(), write_afni_fizt(), write_bucket_data(), write_output(), and write_results().

00265 {
00266    char *ch ;
00267 
00268    if( argc < 2 || argv == NULL || !ISVALID_DSET(dset) ) return ;
00269 
00270    ch = tross_commandline( pname , argc , argv ) ; if( ch == NULL ) return ;
00271    tross_Append_History( dset , ch ) ;
00272    free(ch) ; return ;
00273 }

void tross_multi_Append_History THD_3dim_dataset   dset,
...   
 

Append multiple strings to the History, all on one line. Usage:

  • tross_multi_Append_History(dset,str1,str2,str3,NULL) ;
  • As many str variables as desired (at least 1), of type char *, can be passed in.
  • The last one must be NULL. ------------------------------------------------------------------------------

Definition at line 379 of file thd_notes.c.

References AFMALL, AFREALL, free, nc, and tross_Append_History().

Referenced by basis_write_iresp(), basis_write_sresp(), output_ts_array(), write_afni_data(), and write_ts_array().

00380 {
00381    va_list vararg_ptr ;
00382    int nstr=0 , nc , first=1 , ii ;
00383    char * str , * cpt ;
00384 
00385    va_start( vararg_ptr , dset ) ;
00386 
00387    str = AFMALL(char, 4) ; nstr = 0 ; str[0] = '\0' ;
00388    while(1){
00389       cpt = va_arg( vararg_ptr , char * ) ; if( cpt == NULL ) break ;
00390       nc = strlen(cpt) ;                    if( nc  == 0    ) continue ;
00391       nstr += nc ; str = AFREALL(str, char, nstr+8 ) ;
00392       if( !first ) strcat(str," ; ") ;
00393       strcat(str,cpt) ; first = 0 ;
00394    }
00395 
00396    va_end( vararg_ptr ) ;
00397 
00398    nstr = strlen(str) ;
00399    if( nstr > 0 ){
00400       for( ii=0 ; ii < nstr ; ii++ )
00401          if( str[ii]=='\n' || str[ii]=='\f' || str[ii]=='\r' || str[ii]=='\v' )
00402             str[ii] = ' ' ;
00403 
00404       tross_Append_History( dset , str ) ;
00405    }
00406 
00407    free(str) ; return ;
00408 }

void tross_Replace_History THD_3dim_dataset   dset,
char *    ch
 

Erase the old History and replace it with this one. 09 Dec 2000 - use this wisely. -----------------------------------------------------------------------------

Definition at line 310 of file thd_notes.c.

References THD_3dim_dataset::dblk, free, ISVALID_DSET, THD_set_string_atr, and tross_Encode_String().

Referenced by main().

00311 {
00312    char * cn ;
00313 
00314    if( !ISVALID_DSET(dset) || ch == NULL ) return ;
00315 
00316    cn = tross_Encode_String(ch) ; if( cn == NULL ) return ;
00317    THD_set_string_atr(dset->dblk, "HISTORY_NOTE", cn);
00318    free(cn) ; return ;
00319 }

void tross_Store_Note THD_3dim_dataset   dset,
int    inote,
char *    cn
 

Store string at location inote; if inote > number of notes now present, gets added at the end of the list; otherwise, replaces existing note -------------------------------------------------------------------------------

Definition at line 434 of file thd_notes.c.

References THD_3dim_dataset::dblk, free, ATR_int::in, ISVALID_DSET, MAX_DSET_NOTES, THD_find_int_atr(), THD_set_string_atr, tross_Add_Note(), tross_datetime(), and tross_Encode_String().

Referenced by NOTES_save_CB().

00435 {
00436    ATR_int *notecount;
00437    int num_notes;
00438    ATR_string *note ;
00439    char note_name[20], *ch ;
00440 
00441    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ||
00442                               cn == NULL || cn[0] == '\0'            ) return ;
00443 
00444    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00445    if (notecount == NULL){ tross_Add_Note( dset , cn ) ; return ; }
00446    num_notes = notecount->in[0];
00447    if( inote > num_notes ){ tross_Add_Note( dset , cn ) ; return ; }
00448 
00449    sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00450    ch = tross_Encode_String(cn) ; if( ch == NULL ) return ;
00451    THD_set_string_atr(dset->dblk, note_name, ch);
00452    free(ch) ;
00453 
00454    ch = tross_datetime() ;
00455    sprintf(note_name, "NOTE_DATE_%03d", inote) ;
00456    THD_set_string_atr(dset->dblk, note_name, ch);
00457    free(ch);
00458 
00459    return ;
00460 }

char* tross_username void   
 

Definition at line 88 of file thd_notes.c.

References AFMALL, and NNAME.

Referenced by tross_Append_History(), and XSAVE_output().

00089 {
00090    uid_t uu = getuid() ;
00091    struct passwd * pwd = getpwuid(uu) ;
00092    char * cn = AFMALL(char, NNAME) ;
00093 
00094    if( pwd == NULL ) strcpy(cn,"nobody") ;
00095    else              strcpy(cn,pwd->pw_name) ;
00096    return cn ;
00097 }

void TRUST_addhost char *   
 

Definition at line 135 of file thd_trusthost.c.

References add_TRUST_host(), host_num, init_TRUST_list(), and NI_add_trusted_host().

Referenced by ENV_trusthost().

00136 {
00137    if( hostname == NULL || hostname[0] == '\0' ) return ;
00138    if( host_num == 0 ) init_TRUST_list() ;
00139    add_TRUST_host(hostname) ;
00140 #ifdef USE_NIML
00141    NI_add_trusted_host(hostname) ;
00142 #endif
00143    return ;
00144 }

int TRUST_host char *   
 

Definition at line 150 of file thd_trusthost.c.

References host_list, host_num, and init_TRUST_list().

Referenced by AFNI_plugout_workproc(), MAIN_workprocess(), and RT_check_listen().

00151 {
00152    int ii ;
00153 
00154    if( host_num == 0 ) init_TRUST_list() ;
00155 
00156    if( hostid == NULL || hostid[0] == '\0' ) return 0 ;
00157 
00158    for( ii=0 ; ii < host_num ; ii++ )
00159       if( strstr(hostid,host_list[ii]) == hostid ) return 1 ;
00160 
00161    return 0 ;
00162 }

void ts_shift2 int   ,
int   ,
float   ,
float *   ,
float   ,
float *   
 

Definition at line 651 of file thd_shift2.c.

References ts_shift().

Referenced by SHIFT_set_method().

00652 {
00653                    ts_shift( n , af , f ) ;
00654    if( g != NULL ) ts_shift( n , ag , g ) ;
00655    return ;
00656 }

int TT_load_atlas void   
 

Definition at line 44 of file thd_ttatlas_query.c.

References AFMALL, ENTRY, free, getenv(), have_dseTT, my_getenv(), RETURN, THD_MAX_NAME, and THD_open_one_dataset().

Referenced by AFNI_ttatlas_query(), DRAW_make_widgets(), TT_retrieve_atlas(), TT_retrieve_atlas_big(), TT_retrieve_atlas_either(), and TT_whereami().

00045 {
00046    char *epath, *elocal, ename[THD_MAX_NAME], dname[THD_MAX_NAME], *eee ;
00047    int epos , ll , ii , id ;
00048 
00049 ENTRY("TT_load_atlas") ;
00050 
00051    if( have_dseTT >= 0 ) RETURN(have_dseTT) ;  /* for later calls */
00052 
00053    have_dseTT = 0 ;  /* don't have it yet */
00054 
00055    /*----- 20 Aug 2001: see if user specified alternate database -----*/
00056 
00057    epath = getenv("AFNI_TTATLAS_DATASET") ;
00058    if( epath != NULL ){
00059      dseTT = THD_open_one_dataset( epath ) ;  /* try to open it */
00060      if( dseTT != NULL ){                     /* got it!!! */
00061        have_dseTT = 1; RETURN(1);
00062      }
00063    }
00064 
00065    /*----- get path to search -----*/
00066 
00067                        epath = getenv("AFNI_PLUGINPATH") ;
00068    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
00069    if( epath == NULL ) epath = getenv("PATH") ;
00070    if( epath == NULL ) RETURN(0) ;
00071 
00072    /*----- copy path list into local memory -----*/
00073 
00074    ll = strlen(epath) ;
00075    elocal = AFMALL(char, sizeof(char) * (ll+2) ) ;
00076 
00077    /*----- put a blank at the end -----*/
00078 
00079    strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ;
00080 
00081    /*----- replace colons with blanks -----*/
00082 
00083    for( ii=0 ; ii < ll ; ii++ )
00084      if( elocal[ii] == ':' ) elocal[ii] = ' ' ;
00085 
00086    /*----- extract blank delimited strings;
00087            use as directory names to look for atlas -----*/
00088 
00089    epos = 0 ;
00090 
00091    do{
00092       ii = sscanf( elocal+epos , "%s%n" , ename , &id ); /* next substring */
00093       if( ii < 1 ) break ;                               /* none -> done   */
00094 
00095       epos += id ;                                 /* char after last scanned */
00096 
00097       ii = strlen(ename) ;                         /* make sure name has   */
00098       if( ename[ii-1] != '/' ){                    /* a trailing '/' on it */
00099           ename[ii]  = '/' ; ename[ii+1] = '\0' ;
00100       }
00101       strcpy(dname,ename) ;
00102       strcat(dname,"TTatlas+tlrc") ;               /* add dataset name */
00103 
00104       dseTT = THD_open_one_dataset( dname ) ;      /* try to open it */
00105 
00106       if( dseTT != NULL ){                         /* got it!!! */
00107          free(elocal); have_dseTT = 1; RETURN(1);
00108       }
00109 
00110       strcpy(dname,ename) ;           /* 21 Jul 2005: NIfTI-1.1 version? */
00111       strcat(dname,"TTatlas.nii.gz") ;
00112       dseTT = THD_open_one_dataset( dname ) ;
00113       if( dseTT != NULL ){ free(elocal); have_dseTT = 1; RETURN(1); }
00114 
00115    } while( epos < ll ) ;  /* scan until 'epos' is after end of epath */
00116 
00117    free(elocal) ; RETURN(0) ; /* got here -> didn't find it */
00118 }

void TT_purge_atlas void   
 

Definition at line 124 of file thd_ttatlas_query.c.

References PURGE_DSET.

00125 {
00126   PURGE_DSET(dseTT) ; return ;
00127 }

void TT_purge_atlas_big void   
 

Definition at line 129 of file thd_ttatlas_query.c.

References DSET_delete.

00130 {
00131    if( dseTT_big != NULL ){ DSET_delete(dseTT_big) ; dseTT_big = NULL ; }
00132    return ;
00133 }

THD_3dim_dataset* TT_retrieve_atlas void   
 

Definition at line 14 of file thd_ttatlas_query.c.

References have_dseTT, and TT_load_atlas().

Referenced by AFNI_ttatlas_overlay(), RCREND_func_widgets(), RCREND_overlay_ttatlas(), REND_func_widgets(), and REND_overlay_ttatlas().

00015 {
00016    if( have_dseTT < 0 ) TT_load_atlas() ;
00017    return dseTT ;                         /* might be NULL */
00018 }

THD_3dim_dataset* TT_retrieve_atlas_big void   
 

Definition at line 22 of file thd_ttatlas_query.c.

References DSET_unload, have_dseTT, THD_zeropad(), and TT_load_atlas().

00023 {
00024    if( dseTT_big != NULL ) return dseTT_big ;
00025    if( have_dseTT < 0    ) TT_load_atlas() ;
00026    if( dseTT == NULL     ) return NULL ;
00027    dseTT_big = THD_zeropad( dseTT , 10,0,0,0,0,0 , "TTatlas_big" , 0 ) ;
00028    DSET_unload( dseTT ) ; /* probably won't need again */
00029    return dseTT_big ;
00030 }

THD_3dim_dataset* TT_retrieve_atlas_either void   
 

Definition at line 34 of file thd_ttatlas_query.c.

References have_dseTT, and TT_load_atlas().

Referenced by DRAW_ttatlas_CB().

00035 {
00036    if( dseTT_big != NULL ) return dseTT_big ;
00037    if( dseTT     != NULL ) return dseTT     ;
00038    if( have_dseTT < 0    ) TT_load_atlas()  ;
00039    return dseTT ;
00040 }

char* TT_whereami float   ,
float   ,
float   
 

Definition at line 144 of file thd_ttatlas_query.c.

References ADDTO_SARR, AFMALL, THD_string_array::ar, DESTROY_SARR, DSET_BRICK_ARRAY, DSET_load, DSET_NX, DSET_NY, DSET_NZ, ENTRY, MCW_cluster::i, INIT_SARR, MCW_cluster::j, MCW_cluster::k, LOAD_FVEC3, MCW_cluster::mag, MAX_FIND, MCW_build_mask(), MCW_sort_cluster(), TTO_point::name, THD_string_array::num, MCW_cluster::num_pt, nz, RETURN, swap, TTO_point::tdval, TEMP_FVEC3, THD_3dmm_to_3dind(), THD_tta_to_mni(), TT_load_atlas(), TTO_COUNT, TTO_list, UNLOAD_FVEC3, UNLOAD_IVEC3, and WAMIRAD.

Referenced by AFNI_ttatlas_query(), and main().

00145 {
00146    int ii,kk , ix,jy,kz , nx,ny,nz,nxy , aa,bb,cc , ff,b2f,b4f,rff ;
00147    THD_ivec3 ijk ;
00148    byte *b2 , *b4 ;
00149    THD_string_array *sar ;
00150    char *b2lab , *b4lab ;
00151    char lbuf[256] , *rbuf ;
00152    int nfind, b2_find[MAX_FIND], b4_find[MAX_FIND], rr_find[MAX_FIND] ;
00153 
00154    THD_3dim_dataset * dset ; /* 01 Aug 2001 */
00155 
00156 ENTRY("TT_whereami") ;
00157 
00158    /*-- setup stuff: load atlas dataset, prepare search mask --*/
00159 
00160    if( dseTT == NULL ){
00161       ii = TT_load_atlas() ; if( ii == 0 ) RETURN(NULL) ;
00162    }
00163 
00164    /* 01 Aug 2001: maybe use big dataset (so don't need both in memory) */
00165 
00166    dset = (dseTT_big != NULL) ? dseTT_big : dseTT ;
00167 
00168 #if 0
00169 if( dset == dseTT_big ) fprintf(stderr,"TT_whereami using dseTT_big\n") ;
00170 else                    fprintf(stderr,"TT_whereami using dseTT\n") ;
00171 #endif
00172 
00173    DSET_load(dset) ;
00174    b2 = DSET_BRICK_ARRAY(dset,0) ; if( b2 == NULL ) RETURN(NULL) ;
00175    b4 = DSET_BRICK_ARRAY(dset,1) ; if( b4 == NULL ) RETURN(NULL) ;
00176 
00177    if( wamiclust == NULL ){
00178       wamiclust = MCW_build_mask( 0,0,0 , 1.0,1.0,1.0 , WAMIRAD ) ;
00179       if( wamiclust == NULL ) RETURN(NULL) ;  /* should not happen! */
00180 
00181       for( ii=0 ; ii < wamiclust->num_pt ; ii++ )       /* load radius */
00182          wamiclust->mag[ii] = (int)rint(sqrt((double)(
00183                                          wamiclust->i[ii]*wamiclust->i[ii]
00184                                         +wamiclust->j[ii]*wamiclust->j[ii]
00185                                         +wamiclust->k[ii]*wamiclust->k[ii]))) ;
00186 
00187       MCW_sort_cluster( wamiclust ) ;  /* sort by radius */
00188    }
00189 
00190    /*-- find locations near the given one that are in the Atlas --*/
00191 
00192    ijk = THD_3dmm_to_3dind( dset , TEMP_FVEC3(xx,yy,zz) ) ;  /* get indexes */
00193    UNLOAD_IVEC3(ijk,ix,jy,kz) ;                               /* from coords */
00194 
00195    nx = DSET_NX(dset) ;               /* size of TT atlas dataset axes */
00196    ny = DSET_NY(dset) ;
00197    nz = DSET_NZ(dset) ; nxy = nx*ny ;
00198 
00199    nfind = 0 ;
00200 
00201    /*-- check the exact input location --*/
00202 
00203    kk = ix + jy*nx + kz*nxy ;        /* index into brick arrays */
00204    if( b2[kk] != 0 || b4[kk] != 0 ){
00205       b2_find[0] = b2[kk] ;
00206       b4_find[0] = b4[kk] ;
00207       rr_find[0] = 0      ; nfind++ ;
00208    }
00209 
00210    /*-- check locations near it --*/
00211 
00212    for( ii=0 ; ii < wamiclust->num_pt ; ii++ ){
00213 
00214       /* compute index of nearby location, skipping if outside atlas */
00215 
00216       aa = ix + wamiclust->i[ii] ; if( aa < 0 || aa >= nx ) continue ;
00217       bb = jy + wamiclust->j[ii] ; if( bb < 0 || bb >= ny ) continue ;
00218       cc = kz + wamiclust->k[ii] ; if( cc < 0 || cc >= nz ) continue ;
00219 
00220       kk  = aa + bb*nx + cc*nxy ;   /* index into bricks */
00221       b2f = b2[kk] ; b4f = b4[kk] ; /* TT structures markers there */
00222 
00223       if( b2f == 0 && b4f == 0 )                            continue ;
00224 
00225       for( ff=0 ; ff < nfind ; ff++ ){       /* cast out         */
00226          if( b2f == b2_find[ff] ) b2f = 0 ;  /* duplicate labels */
00227          if( b4f == b4_find[ff] ) b4f = 0 ;  /* we already found */
00228       }
00229       if( b2f == 0 && b4f == 0 )                            continue ;
00230 
00231       b2_find[nfind] = b2f ;  /* save what we found */
00232       b4_find[nfind] = b4f ;
00233       rr_find[nfind] = (int) wamiclust->mag[ii] ;
00234       nfind++ ;
00235 
00236       if( nfind == MAX_FIND ) break ;  /* don't find TOO much */
00237    }
00238 
00239    /*-- assemble output string(s) --*/
00240 
00241 #define WAMI_HEAD "+++++++ nearby Talairach Daemon structures +++++++\n"
00242 #define WAMI_TAIL "\n******** Please use results with caution! ********"  \
00243                   "\n******** Brain anatomy is quite variable! ********"  \
00244                   "\n******** The database may contain errors! ********"
00245 
00246    if( nfind == 0 ){
00247       char xlab[24], ylab[24] , zlab[24] ;
00248       THD_fvec3 tv , mv ;
00249       float mx,my,mz ;
00250       char mxlab[24], mylab[24] , mzlab[24] ;
00251 
00252       sprintf(xlab,"%4.0f mm [%c]",-xx,(xx<0.0)?'R':'L') ;
00253       sprintf(ylab,"%4.0f mm [%c]",-yy,(yy<0.0)?'A':'P') ;
00254       sprintf(zlab,"%4.0f mm [%c]", zz,(zz<0.0)?'I':'S') ;
00255 
00256       LOAD_FVEC3(tv,xx,yy,zz);
00257       mv = THD_tta_to_mni(tv); UNLOAD_FVEC3(mv,mx,my,mz);
00258       sprintf(mxlab,"%4.0f mm [%c]",mx,(mx>=0.0)?'R':'L') ;
00259       sprintf(mylab,"%4.0f mm [%c]",my,(my>=0.0)?'A':'P') ;
00260       sprintf(mzlab,"%4.0f mm [%c]",mz,(mz< 0.0)?'I':'S') ;
00261 
00262       rbuf = AFMALL(char, 500) ;
00263       sprintf(rbuf,"%s\n"
00264                    "Focus point=%s,%s,%s {T-T Atlas}\n"
00265                    "           =%s,%s,%s {MNI Brain}\n"
00266                    "\n"
00267                    "***** Not near any region stored in database *****\n" ,
00268               WAMI_HEAD , xlab,ylab,zlab , mxlab,mylab,mzlab ) ;
00269       RETURN(rbuf) ;
00270    }
00271 
00272    /*-- bubble-sort what we found, by radius --*/
00273 
00274    if( nfind > 1 ){  /* don't have to sort only 1 result */
00275      int swap, tmp ;
00276      do{
00277         swap=0 ;
00278         for( ii=1 ; ii < nfind ; ii++ ){
00279            if( rr_find[ii-1] > rr_find[ii] ){
00280              tmp = rr_find[ii-1]; rr_find[ii-1] = rr_find[ii]; rr_find[ii] = tmp;
00281              tmp = b2_find[ii-1]; b2_find[ii-1] = b2_find[ii]; b2_find[ii] = tmp;
00282              tmp = b4_find[ii-1]; b4_find[ii-1] = b4_find[ii]; b4_find[ii] = tmp;
00283              swap++ ;
00284            }
00285         }
00286      } while(swap) ;
00287    }
00288 
00289    /*-- find anatomical label for each found marker, make result string --*/
00290 
00291    INIT_SARR(sar) ; ADDTO_SARR(sar,WAMI_HEAD) ;
00292 
00293    /* 04 Apr 2002: print coordinates (LPI) as well (the HH-PB addition) */
00294 
00295    { char lbuf[128], xlab[24], ylab[24] , zlab[24] ;
00296      sprintf(xlab,"%4.0f mm [%c]",-xx,(xx<0.0)?'R':'L') ;
00297      sprintf(ylab,"%4.0f mm [%c]",-yy,(yy<0.0)?'A':'P') ;
00298      sprintf(zlab,"%4.0f mm [%c]", zz,(zz<0.0)?'I':'S') ;
00299      sprintf(lbuf,"Focus point=%s,%s,%s {T-T Atlas}",xlab,ylab,zlab) ;
00300      ADDTO_SARR(sar,lbuf) ;
00301    }
00302 
00303    /* 29 Apr 2002: print MNI coords as well */
00304 
00305    { THD_fvec3 tv , mv ;
00306      float mx,my,mz ;
00307      char mxlab[24], mylab[24] , mzlab[24] , lbuf[128] ;
00308      LOAD_FVEC3(tv,xx,yy,zz);
00309      mv = THD_tta_to_mni(tv); UNLOAD_FVEC3(mv,mx,my,mz);
00310      sprintf(mxlab,"%4.0f mm [%c]",mx,(mx>=0.0)?'R':'L') ;
00311      sprintf(mylab,"%4.0f mm [%c]",my,(my>=0.0)?'A':'P') ;
00312      sprintf(mzlab,"%4.0f mm [%c]",mz,(mz< 0.0)?'I':'S') ;
00313      sprintf(lbuf,"Focus point=%s,%s,%s {MNI Brain}\n",mxlab,mylab,mzlab) ;
00314      ADDTO_SARR(sar,lbuf) ;
00315    }
00316 
00317    rff = -1 ;  /* rff = radius of last found label */
00318 
00319    for( ff=0 ; ff < nfind ; ff++ ){
00320       b2f = b2_find[ff] ; b4f = b4_find[ff] ; b2lab = NULL ; b4lab = NULL ;
00321 
00322       if( b2f != 0 ){                               /* find label     */
00323          for( ii=0 ; ii < TTO_COUNT ; ii++ )        /* in AFNI's list */
00324             if( b2f == TTO_list[ii].tdval ) break ;
00325          if( ii < TTO_COUNT )                       /* always true? */
00326             b2lab = TTO_list[ii].name ;
00327 
00328          if( b2lab != NULL && xx < 0 && strstr(b2lab,"Left") != NULL ) /* maybe is Right */
00329             b2lab = TTO_list[ii+1].name ;
00330       }
00331 
00332       if( b4f != 0 ){
00333          for( ii=0 ; ii < TTO_COUNT ; ii++ )
00334             if( b4f == TTO_list[ii].tdval ) break ;
00335          if( ii < TTO_COUNT )
00336             b4lab = TTO_list[ii].name ;
00337          if( b4lab != NULL && xx < 0 && strstr(b4lab,"Left") != NULL )
00338             b4lab = TTO_list[ii+1].name ;
00339       }
00340 
00341       if( b2lab == NULL && b4lab == NULL ) continue ;  /* no labels? */
00342 
00343       /* make output label into lbuf */
00344 
00345       lbuf[0] = '\0' ;
00346       if( b2lab != NULL ){
00347          if( rr_find[ff] != rff ){
00348             if( rr_find[ff] > 0 )
00349               sprintf( lbuf , "Within %d mm: %s" , rr_find[ff] , b2lab ) ;
00350             else
00351               sprintf( lbuf , "Focus point: %s" , b2lab ) ;
00352          } else {
00353             sprintf( lbuf , "             %s" , b2lab ) ;
00354          }
00355 
00356          for( kk=strlen(lbuf)-1 ; kk > 0 && lbuf[kk] == '.' ; kk-- )
00357             lbuf[kk] = '\0' ;                  /* trim trailing .'s */
00358       }
00359 
00360       if( b4lab != NULL ){
00361          kk = strlen(lbuf) ;
00362          if( kk > 0 ){
00363             sprintf( lbuf+kk , " -AND- %s" , b4lab ) ;
00364          } else if( rr_find[ff] != rff ){
00365             if( rr_find[ff] > 0 )
00366               sprintf( lbuf , "Within %d mm: %s" , rr_find[ff] , b4lab ) ;
00367             else
00368               sprintf( lbuf , "Focus point: %s" , b4lab ) ;
00369          } else {
00370             sprintf( lbuf , "             %s" , b4lab ) ;
00371          }
00372 
00373          for( kk=strlen(lbuf)-1 ; kk > 0 && lbuf[kk] == '.' ; kk-- )
00374             lbuf[kk] = '\0' ;
00375       }
00376 
00377       ADDTO_SARR(sar,lbuf) ;  /* make a list of labels */
00378 
00379       rff = rr_find[ff] ;  /* save for next time around */
00380    }
00381 
00382    /*- if didn't make any label, must produce something -*/
00383 
00384    if( sar->num == 1 ){    /* shouldn't ever happen */
00385       sprintf(lbuf,"Found %d marked but unlabeled regions???\n",nfind) ;
00386       ADDTO_SARR(sar,lbuf) ;
00387    } else {
00388       ADDTO_SARR(sar,WAMI_TAIL) ;  /* cautionary tail */
00389    }
00390 
00391    /*- convert list of labels into one big multi-line string -*/
00392 
00393    for( nfind=ii=0 ; ii < sar->num ; ii++ ) nfind += strlen(sar->ar[ii]) ;
00394    rbuf = AFMALL(char, nfind + 2*sar->num + 32 ) ; rbuf[0] = '\0' ;
00395    for( ii=0 ; ii < sar->num ; ii++ ){
00396       strcat(rbuf,sar->ar[ii]) ; strcat(rbuf,"\n") ;
00397    }
00398 
00399    DESTROY_SARR(sar) ; RETURN(rbuf) ;
00400 }

char* UNIQ_idcode void   
 

Return a globally unique identifier (I hope). This is a malloc()-ed string of length <= 31 (plus the NUL byte; the whole thing will fit into a char[32] array). The output does not contain any '/'s, so it could be used as a temporary filename. Repeated calls to this function should never return the same string.

Method: Generate a string from the system identfier information and the current time of day. MD5 hash this to a 128 byte code. Base64 encode this to a 22 byte string. Replace '/' with '-' and '+' with '_'. Add 4 character prefix (1st 3 characters of environment variable IDCODE_PREFIX plus '_').

Sample output: "XYZ_VdfGpfzy_NlY-2d7tA8Q1w" -------------------------------------------------------------------------

Definition at line 121 of file niml_uuid.c.

Referenced by main(), and UNIQ_idcode_fill().

00122 {
00123    char *buf , *idc ;
00124 
00125    /* get uniq string from system */
00126 
00127    buf = get_UNIQ_string() ;
00128 
00129    /* make the output by hashing the string in buf */
00130 
00131    idc = UNIQ_hashcode( buf ) ;
00132 
00133    /* free workspace and get outta here */
00134 
00135    free(buf) ; return idc ;
00136 }

void UNIQ_idcode_fill char *    idc
 

Fill a user-supplied buffer (length at least 32) with an idcode. That is, idc should point to a char array of length 32 (or more). ------------------------------------------------------------------------

Definition at line 175 of file niml_uuid.c.

00176 {
00177    char *bbb ;
00178    if( idc == NULL ) return ;
00179    bbb = UNIQ_idcode() ;
00180    strcpy(idc,bbb) ; free(bbb) ; return ;
00181 }

THD_3dim_dataset* WINsorize THD_3dim_dataset  ,
int   ,
int   ,
int   ,
float   ,
char *   ,
int   ,
int   ,
byte  
 

Definition at line 16 of file thd_winsor.c.

References abs, ADDTO_CLUSTER, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, CFRAC, DSET_BRICK_ARRAY, DSET_BRICK_TYPE, DSET_load, DSET_NX, DSET_NY, DSET_NZ, EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), free, MCW_cluster::i, MCW_cluster::j, MCW_cluster::k, KILL_CLUSTER, LIM, malloc, MCW_build_mask(), MCW_cluster::num_pt, nz, qsort_sh(), and THD_filename_ok().

Referenced by main().

00020 {
00021    THD_3dim_dataset *outset ;
00022    short *shin , *shout , *di,*dj,*dk , *tmp , val,nval ;
00023    MCW_cluster *cl ;
00024    int jj,kk , krep,kdiff, nx,ny,nz,nxy,nxyz , nd,dd ;
00025    int ip,jp,kp , nx1,ny1,nz1 , verb=1 ;
00026    int nrep_until ;
00027    register int ii,ijk ;
00028 
00029    /*- check inputs -*/
00030 
00031    if( inset == NULL || DSET_BRICK_TYPE(inset,0) != MRI_short ) return NULL ;
00032    DSET_load(inset) ;
00033    if( DSET_BRICK_ARRAY(inset,0) == NULL ) return NULL ;
00034 
00035    if( nrep == 0 ) return NULL ;
00036 
00037    if( nrep < 0 ){ nrep_until = abs(nrep) ; nrep = 999 ; }
00038    else          { nrep_until = 2 ; }
00039 
00040    if( irad < 0.0 ){ verb=0 ; irad = -irad ; }
00041 
00042    if( irad < 1.01 ) irad = 1.01 ;
00043    if( !THD_filename_ok(prefix) ) prefix = "Winsor" ;
00044 
00045    /*- build list of points to use -*/
00046 
00047    cl = MCW_build_mask( 0,0,0 , 1.0,1.0,1.0 , irad ) ;
00048 
00049    if( cl == NULL || cl->num_pt < 6 ){ KILL_CLUSTER(cl); return NULL; }
00050 
00051    ADDTO_CLUSTER(cl,0,0,0,0) ;
00052 
00053    di = cl->i ; dj = cl->j ; dk = cl->k ; nd = cl->num_pt ;
00054 
00055    if( verb ) fprintf(stderr,"+++ WINsorize irad=%f nbhd=%d\n",irad,nd) ;
00056 
00057    /*- make output array -*/
00058 
00059    nx = DSET_NX(inset) ; nx1 = nx-1 ;
00060    ny = DSET_NY(inset) ; ny1 = ny-1 ;
00061    nz = DSET_NZ(inset) ; nz1 = nz-1 ; nxy = nx*ny ; nxyz = nxy*nz ;
00062 
00063    shout = (short *) malloc(sizeof(short)*nxyz) ;
00064    tmp   = (short *) malloc(sizeof(short)*nd) ;
00065 
00066    if( nrep > 1 ){
00067       shin  = (short *) malloc(sizeof(short)*nxyz) ;
00068       memcpy( shin , DSET_BRICK_ARRAY(inset,0) , sizeof(short)*nxyz ) ;
00069    } else {
00070       shin = DSET_BRICK_ARRAY(inset,0) ;
00071    }
00072 
00073    if( cbot <= 0 || cbot >= nd-1 ){
00074       cbot = rint( CFRAC*nd ) ;
00075       if( cbot <= 0 ) cbot = 1 ;
00076       if( verb ) fprintf(stderr,"+++ WINsorize cbot=%d\n",cbot) ;
00077    }
00078    if( ctop <= cbot || cbot >= nd-1 ){
00079       ctop = nd-1-cbot ;
00080       if( verb ) fprintf(stderr,"+++ WINsorize ctop=%d\n",ctop) ;
00081    }
00082 
00083    /*- do the work -*/
00084 
00085    for( krep=0 ; krep < nrep ; krep++ ){
00086 
00087       kdiff = 0 ;  /* count of how many voxels were changed */
00088 
00089       for( kk=0 ; kk < nz ; kk++ ){        /* loops over 3D voxel indices */
00090          for( jj=0 ; jj < ny ; jj++ ){
00091             ijk = jj*nx+kk*nxy ;
00092             for( ii=0 ; ii < nx ; ii++,ijk++ ){
00093 
00094                if( mask != NULL && !mask[ijk] ){ shout[ijk]=shin[ijk]; continue; }
00095 
00096                val = shin[ijk] ;                        /* current voxel */
00097 
00098                if( clipval > 0 && val <= clipval )      /* 19 Oct 2001 */
00099                   val = shout[ijk] = 0 ;
00100 
00101                if( keep_zero && val == 0 ) continue ;   /* don't filter 0 */
00102 
00103                for( dd=0 ; dd < nd ; dd++ ){            /* loop over nbhd */
00104                   ip = ii+di[dd] ; ip = LIM(ip,0,nx1) ;
00105                   jp = jj+dj[dd] ; jp = LIM(jp,0,ny1) ;
00106                   kp = kk+dk[dd] ; kp = LIM(kp,0,nz1) ;
00107                   tmp[dd] = shin[ip+jp*nx+kp*nxy] ;
00108                }
00109 
00110                qsort_sh( nd , tmp ) ;
00111 
00112                shout[ijk] = nval = LIM(val,tmp[cbot],tmp[ctop]) ;
00113 
00114                if( nval != val ) kdiff++ ;
00115             }
00116          }
00117       }
00118 
00119       /* prepare for next iteration */
00120 
00121       if( verb ) fprintf(stderr,"+++ WINsorize iter%2d: # changed=%d\n",krep+1,kdiff) ;
00122 
00123       if( kdiff < nrep_until ) break ;
00124 
00125       if( krep < nrep-1 )
00126          memcpy( shin , shout , sizeof(short)*nxyz ) ;
00127    }
00128 
00129    /*- toss the trashola */
00130 
00131    KILL_CLUSTER(cl) ;
00132    free(tmp) ;
00133    if( shin != DSET_BRICK_ARRAY(inset,0) ) free(shin) ;
00134 
00135    /*- make output dataset */
00136 
00137    outset = EDIT_empty_copy( inset )  ;
00138 
00139    EDIT_dset_items( outset ,
00140                        ADN_prefix , prefix ,
00141                        ADN_nvals  , 1 ,
00142                        ADN_ntt    , 0 ,
00143                     ADN_none ) ;
00144 
00145    EDIT_substitute_brick( outset , 0 , MRI_short , shout ) ;
00146 
00147    return outset ;
00148 }

Variable Documentation

int ANAT_ival_zero[] = { 0,0,0,0,0,0,0,0,0,0,0,0 , 0 } [static]
 

Definition at line 1950 of file 3ddata.h.

int ANAT_nvals[] = { 1,1,1,1,1,1,1,1,1,1,1,1 , 1 } [static]
 

Definition at line 1949 of file 3ddata.h.

char* ANAT_prefixstr[] [static]
 

Initial value:

Definition at line 1920 of file 3ddata.h.

char* ANAT_typestr[] [static]
 

Initial value:

Definition at line 1913 of file 3ddata.h.

char* ATR_typestr[] [static]
 

Initial value:

 {
   "string-attribute" , "float-attribute" , "integer-attribute"
}
Things to look for in the .HEAD file; these define start of an attribute.

Definition at line 435 of file 3ddata.h.

char* DATASET_typestr[] [static]
 

Initial value:

Definition at line 1539 of file 3ddata.h.

THD_dmat33 DBLE_mat_to_dicomm( THD_3dim_dataset * )
 

char* DSET_prefixstr[NUM_DSET_TYPES] [static]
 

Initial value:

Definition at line 1929 of file 3ddata.h.

char* FUNC_descriptor[] [static]
 

Initial value:

Definition at line 1764 of file 3ddata.h.

int FUNC_ival_fim[] = { 0, 0,0,0,0,0,0,0,0,0,0, 0 } [static]
 

Definition at line 1776 of file 3ddata.h.

int FUNC_ival_thr[] = { FIMTHR, 1,1,1,1,1,1,1,1,1,1, 0 } [static]
 

Definition at line 1780 of file 3ddata.h.

char* FUNC_label[] [static]
 

Initial value:

Definition at line 1758 of file 3ddata.h.

char* FUNC_label_stat_aux[] [static]
 

Initial value:

 {
   "N/A" , "N/A" ,                                      
   "SAMPLES  FIT-PARAMETERS  ORT-PARAMETERS" ,          
   "DEGREES-of-FREEDOM" ,                               
   "NUMERATOR and DENOMINATOR DEGREES-of-FREEDOM" ,     
   "N/A" ,                                              
   "DEGREES-of-FREEDOM" ,                               
   "A (numerator) and B (denominator)" ,                
   "NUMBER-of-TRIALS and PROBABILITY-per-TRIAL" ,       
   "SHAPE and SCALE" ,                                  
   "MEAN" ,                                             
   "N/A"                                                
}
Labels describing the parameters needed for each statistic code.

Definition at line 1803 of file 3ddata.h.

int FUNC_need_stat_aux[] [static]
 

Initial value:

 { 0 , 0 , 3 , 1 , 2 ,
                                    0 , 1 , 2 , 2 , 2 , 1 ,
                                    0 }
Number of statistical parameters needed for each statistic code.

Definition at line 1797 of file 3ddata.h.

int FUNC_nvals[] = { 1, 2,2,2,2,2,2,2,2,2,2, 1 } [static]
 

Definition at line 1775 of file 3ddata.h.

char* FUNC_prefixstr[] [static]
 

Initial value:

Definition at line 1729 of file 3ddata.h.

int FUNC_scale_byte[] [static]
 

Initial value:

Definition at line 1750 of file 3ddata.h.

int FUNC_scale_short[] [static]
 

Initial value:

Definition at line 1742 of file 3ddata.h.

float FUNC_topval[] [static]
 

Initial value:

Definition at line 1736 of file 3ddata.h.

char* FUNC_typestr[] [static]
 

Initial value:

Definition at line 1723 of file 3ddata.h.

char* MAPPING_typestr[] [static]
 

Initial value:

Definition at line 488 of file 3ddata.h.

MCW_idcode MCW_new_idcode(void) void   
 

Routine to return a (hopefully) unique ID code to be used to identify a dataset to other datasets. -------------------------------------------------------------------------

Definition at line 16 of file thd_idcode.c.

Referenced by adwarp_follower_dataset(), AFNI_follower_dataset(), AFNI_init_warp(), AFNI_read_images(), EDIT_empty_copy(), main(), T3D_save_file_CB(), and THD_3dim_from_block().

00017 {
00018    MCW_idcode newid ;
00019    time_t tnow ;
00020    int nn ;
00021 
00022    UNIQ_idcode_fill( newid.str ) ;  /* thd_md5.c */
00023 
00024    tnow = time(NULL) ;
00025    MCW_strncpy( newid.date , ctime(&tnow) , MCW_IDDATE ) ;
00026    nn = strlen(newid.date) ;
00027    if( nn > 0 && newid.date[nn-1] == '\n' ) newid.date[nn-1] = '\0' ;
00028 
00029    return newid ;
00030 }

char ORIENT_first[] = "RLPAIS" [static]
 

Definition at line 1248 of file 3ddata.h.

char* ORIENT_shortstr[] [static]
 

Initial value:

 {
   "R-L" , "L-R" , "P-A" , "A-P" , "I-S" , "S-I" , "GEN"
}

Definition at line 1233 of file 3ddata.h.

char ORIENT_sign[] = "+--++-" [static]
 

Determines if orientation code (0..5) is Dicom positive or negative.

Definition at line 1246 of file 3ddata.h.

char* ORIENT_tinystr[] [static]
 

Initial value:

 {
   "RL" , "LR" , "PA" , "AP" , "IS" , "SI" , "??"
}

Definition at line 1237 of file 3ddata.h.

char* ORIENT_typestr[] [static]
 

Initial value:

Definition at line 1228 of file 3ddata.h.

char ORIENT_xyz[] = "xxyyzzg" [static]
 

Definition at line 1241 of file 3ddata.h.

int ORIENT_xyzint[] = { 1,1 , 2,2 , 3,3 , 666 } [static]
 

Definition at line 1250 of file 3ddata.h.

char* RESAM_shortstr[] = { "NN" , "Li" , "Cu" , "Bk" } [static]
 

Definition at line 770 of file 3ddata.h.

char* RESAM_typestr[] [static]
 

Initial value:

Definition at line 765 of file 3ddata.h.

THD_mat33 SNGL_mat_to_dicomm( THD_3dim_dataset * )
 

THD_warp tempA_warp [static]
 

Temporary warp.

Definition at line 840 of file 3ddata.h.

int THD_align_aflags[MARKS_MAXFLAG] [static]
 

Initial value:

Definition at line 604 of file 3ddata.h.

char* THD_align_help[NMARK_ALIGN] [static]
 

Initial value:

 {
   "This is the uppermost point\n"
   "on the anterior commisure,\n"
   "in the mid-sagittal plane." ,

   "This is the rearmost point\n"
   "on the anterior commisure,\n"
   "in the mid-sagittal plane.\n"
   "[Just a couple mm behind and\n"
   " below the AC superior edge.]" ,

   "This is the bottommost point\n"
   "on the posterior commissure,\n"
   "in the mid-sagittal plane." ,

   "You must also specify two other points in the\n"
   "mid-sagittal plane, ABOVE the corpus callosum\n"
   "(i.e., in the longitudinal fissure).  These\n"
   "points are needed to define the vertical plane." ,

   "You must also specify two other points in the\n"
   "mid-sagittal plane, ABOVE the corpus callosum\n"
   "(i.e., in the longitudinal fissure).  These\n"
   "points are needed to define the vertical plane." ,

}
Help for orig->acpc markers.

Definition at line 626 of file 3ddata.h.

char* THD_align_label[NMARK_ALIGN] [static]
 

Initial value:

 {
   "AC superior edge"     ,
   "AC posterior margin"  ,
   "PC inferior edge"     ,
   "First mid-sag pt"     ,
   "Another mid-sag pt"
}
Labels for orig->acpc markers.

Definition at line 616 of file 3ddata.h.

int THD_bounding_aflags[MARKS_MAXFLAG] [static]
 

Initial value:

Definition at line 659 of file 3ddata.h.

char* THD_bounding_help[NMARK_BOUNDING] [static]
 

Initial value:

 {
"The frontmost point of the frontal cortex;\n"
"needed for brain length [atlas y = -70 mm]" ,

"The hindmost point of the occipital cortex;\n"
"needed for brain length [atlas y = +102 mm]" ,

"The topmost point of the parietal cortex;\n"
"needed for brain height [atlas z = +74 mm]" ,

"The lowest point of the temporal cortex;\n"
"needed for brain height [atlas z = -42 mm]" ,

"The most lateral (left) point of the parietotemporal cortex;\n"
"needed for brain width [atlas x = +68 mm]" ,

"The most lateral (right) point of the parietotemporal cortex;\n"
"needed for brain width [atlas x = -68 mm]"

}
Help for acpc->tlrc markers.

Definition at line 711 of file 3ddata.h.

char* THD_bounding_label[NMARK_BOUNDING] [static]
 

Initial value:

 {
   "Most anterior point"  ,
   "Most posterior point" ,
   "Most superior point"  ,
   "Most inferior point"  ,
   "Most left point"      ,
   "Most right point"
}
Labels for acpc->tlrc markers.

Definition at line 700 of file 3ddata.h.

THD_fvec3 THD_dataset_center( THD_3dim_dataset * )
 

THD_brick_stats THD_get_brick_stats( MRI_IMAGE * )
 

char tmp_dblab[8] [static]
 

30 Nov 1997 *

Definition at line 2513 of file 3ddata.h.

char* UNITS_TYPE_labelstring[] = { "ms" , "s" , "Hz" } [static]
 

Definition at line 1359 of file 3ddata.h.

char* VIEW_codestr[] [static]
 

Initial value:

Definition at line 1571 of file 3ddata.h.

char* VIEW_typestr[] [static]
 

Initial value:

Definition at line 1566 of file 3ddata.h.

char* WARP_typestr[] [static]
 

Initial value:

Definition at line 744 of file 3ddata.h.

 

Powered by Plone

This site conforms to the following standards: