00001 function [err,Info, BRIKinfo] = BrikInfo (BrickName)
00002 %
00003 % [err,Info] = BrikInfo (BrickName)
00004 %
00005 %Purpose:
00006 %
00007 % returns some field values in the .HEAD files
00008 %
00009 %Input Parameters:
00010 % Brick filename
00011 % (also works for 1D files but Info has very limited info.
00012 % You should really avoid using BrikInfo on 1D file
00013 % because the 1D file is read in its entirety (and then cleared)
00014 % before Info can be returned. Better used BrikLoad directly or
00015 % Read_1D)
00016 %
00017 %
00018 %Output Parameters:
00019 % err : 0 No Problem
00020 % : 1 Mucho Problems
00021 % Info is a structure with the following fields
00022 % Fieldnames in UPPER CASE correspond to the fields in AFNI
00023 % Field names in lower case correspond to some interpretation of the uppercase ones
00024 % .RootName : the brik name without .HEAD or .BRIK.
00025 % .TypeName: The interpretation of BRICK_TYPES (short, int, floats, etc...)
00026 % .TypeBytes : The corresponding byte size of BRICK_TYPES
00027 % .ByteOrder: interpretation of BYTEORDER_STRING
00028 % .Orientation : interpretation of ORIENT_SPECIFIC, Orientation(:,1)' forms the three letter orientation code
00029 % The ith row of Orientation describes the orientation along that dimension.
00030 % see AFNI's README.attributes for a complete description of these fields
00031 % MANDATORY FIELDS AS SPECIFIED IN: ~cox/README.attributes (added April 6 2001)
00032 % .DATASET_RANK : ASK BOB. I think the first is always 3 (3D) and the other is the number of sub-bricks
00033 % .DATASET_DIMENSIONS : Number of voxels in each of the three dimensions
00034 % .TYPESTRING: Determines if the data set is of type Anat (underlay) or Func (overlay)
00035 % .SCENE_DATA : The three integer codes describing the dataset type
00036 % .ORIENT_SPECIFIC : orintation code
00037 % .ORIGIN : The xyz coordinates of the center of the (0, 0, 0) voxel in the data set
00038 % .DELTA : the increment (in mm) to go from one voxel to the next (could be +ve or -ve depending on slices)
00039 % .TAXIS_NUMS: see readme file
00040 % .TAXIS_FLOATS
00041 % .TAXIS_OFFSETS
00042 % ALMOST MANDATORY FIELDS
00043 % .IDCODE_STRING
00044 % .IDCODE_DATE
00045 % .BYTEORDER_STRING : Byte order string
00046 % .BRICK_STATS : range of values in brick (min to max)
00047 % (Do not apply the scaling factor to these values)
00048 % .BRICK_TYPES : types of values in .BRIK
00049 % .BRICK_FLOAT_FACS : float factors to apply to bricks for recovering original values
00050 % .BRICK_LABS : The Sub-brick labels (~delimited)
00051 % .BRICK_STATAUX : Auxilliary Statistical Information
00052 % .STAT_AUX
00053 % .HISTORY_NOTE
00054 % .NOTES_COUNT
00055 % .NOTE_NUMBER_001
00056 % .TAGALIGN_MATVEC
00057 % .VOLREG_CENTER_OLD
00058 % .VOLREG_CENTER_BASE
00059 % .VOLREG_ROTPARENT_IDCODE
00060 % .VOLREG_ROTPARENT_NAME
00061 % .VOLREG_GRIDPARENT_IDCODE
00062 % .VOLREG_GRIDPARENT_NAME
00063 % .VOLREG_INPUT_IDCODE
00064 % .VOLREG_INPUT_NAME
00065 % .VOLREG_BASE_IDCODE
00066 % .VOLREG_BASE_NAME
00067 % .VOLREG_ROTCOM_NUM
00068 % .VOLREG_MATVEC_xxxxxx
00069 % .VOLREG_ROTCOM_xxxxxx
00070 % .IDCODE_ANAT_PARENT
00071 % .TO3D_ZPAD
00072 % .IDCODE_WARP_PARENT
00073 % .WARP_TYPE
00074 % .WARP_DATA
00075 % .MARKS_XYZ
00076 % .MARKS_LAB
00077 % .MARKS_HELP
00078 % .MARKS_FLAGS
00079 % .TAGSET_NUM
00080 % .TAGSET_FLOATS
00081 % .TAGSET_LABELS
00082 % .LABEL_1
00083 % .LABEL_2
00084 % .DATASET_NAME
00085 % .DATASET_KEYWORDS
00086 % .BRICK_KEYWORDS
00087 % .HISTORY_NOTE
00088 % .NOTES_COUNT
00089 % .NOTE_NUMBER_xxx
00090 %
00091 % To implement in the future,
00092 % VOLREG_MATVEC_xxxxxx , VOLREG_ROTCOM_xxxxxx
00093 %
00094 % The following fields were added to support 1D file format.
00095 % .FileFormat: 'BRIK' ('1D' is allowed for 1D files but 1D files do not use BrikInfo)
00096 % .Extension_1D: The extension of the 1D filename
00097 % BrikLoad and WriteBrik now read and write 1D files
00098 %
00099 %Key Terms:
00100 % The 1st, second and third dimensions refer to the dimensions the slices were entered into to3d
00101 %More Info :
00102 % afni's README.attributes
00103 %
00104 % Author : Ziad Saad
00105 % Date : Sun Oct 17 00:13:49 CDT 1999 , Major modification, April 06 2001
00106
00107
00108 %Define the function name for easy referencing
00109 FuncName = 'BrikInfo';
00110
00111 %Debug Flag
00112 DBG = 1;
00113
00114 %initailize return variables
00115 err = 1;
00116 Info = [];
00117
00118 %check if this is a 1D file ..
00119 is1D = 0;
00120 [St, xtr] = Remove1DExtension(BrickName);
00121 if (~isempty(xtr)),
00122 is1D = 1;
00123 end
00124
00125 if (is1D), % 1D land
00126 [err, V, Info] = Read_1D(BrickName, 1);
00127 if (err),
00128 ErrMessage = sprintf ('%s: Failed to read %s file', FuncName, BrickName);
00129 err = ErrEval(FuncName,'Err_1D file could not be read');
00130 return;
00131 end
00132 clear V; %biggest waste since 2002
00133 return;
00134 end
00135
00136
00137 vtmp = findstr(BrickName,'.BRIK');
00138 if (~isempty(vtmp)), %remove .BRIK
00139 BrickName = BrickName(1:vtmp(1)-1);
00140 end
00141
00142 vtmp = findstr(BrickName,'.HEAD');
00143 if (isempty(vtmp)), %add .HEAD
00144 BrickName = sprintf('%s.HEAD',BrickName);
00145 end
00146
00147
00148 if (exist(BrickName) ~= 2),
00149 err = ErrEval(FuncName,'Err_Could not find data set');
00150 return;
00151 end
00152
00153 %store the name without the extension
00154 vtmp = findstr(BrickName,'.HEAD');
00155 Info.RootName = BrickName(1:vtmp-1);
00156
00157 fidin=fopen(BrickName,'r');
00158 if (fidin < 0), err = ErrEval(FuncName,'Err_Could not read .HEAD file'); return; end
00159 BRIKinfo = fscanf(fidin,'%c');
00160 fclose(fidin);
00161 N_BRIKinfo = length(BRIKinfo);
00162
00163 %get subBrik info
00164 %Nx, Ny, Nz
00165 [err,Info.DATASET_DIMENSIONS] = BrikInfo_SectionValue (BRIKinfo, 'DATASET_DIMENSIONS');
00166
00167 %DATASET_RANK
00168 [err, Info.DATASET_RANK] = BrikInfo_SectionValue(BRIKinfo, 'DATASET_RANK');
00169
00170 %BRICK_TYPES
00171 [err, Info.BRICK_TYPES] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_TYPES');
00172
00173 %BRICK_STATS
00174 [err, Info.BRICK_STATS] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_STATS');
00175
00176 %BRICK_FLOAT_FACS
00177 [err, Info.BRICK_FLOAT_FACS] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_FLOAT_FACS');
00178
00179 %BYTEORDER_STRING
00180 [err, Info.BYTEORDER_STRING] = BrikInfo_SectionValue(BRIKinfo, 'BYTEORDER_STRING');
00181
00182 %ORIENT_SPECIFIC
00183 [err, Info.ORIENT_SPECIFIC] = BrikInfo_SectionValue(BRIKinfo, 'ORIENT_SPECIFIC');
00184
00185 %ORIGIN
00186 [err, Info.ORIGIN] = BrikInfo_SectionValue(BRIKinfo, 'ORIGIN');
00187
00188 %DELTA
00189 [err, Info.DELTA] = BrikInfo_SectionValue(BRIKinfo, 'DELTA');
00190
00191 %BRICK_LABS
00192 [err, Info.BRICK_LABS] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_LABS');
00193
00194 %BRICK_KEYWORDS
00195 [err, Info.BRICK_KEYWORDS] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_KEYWORDS');
00196
00197 %SCENE_DATA
00198 [err, Info.SCENE_DATA] = BrikInfo_SectionValue(BRIKinfo, 'SCENE_DATA');
00199
00200 %TYPESTRING
00201 [err, Info.TYPESTRING] = BrikInfo_SectionValue(BRIKinfo, 'TYPESTRING');
00202
00203 %TAXIS_NUMS
00204 [err, Info.TAXIS_NUMS] = BrikInfo_SectionValue(BRIKinfo, 'TAXIS_NUMS');
00205
00206 %TAXIS_FLOATS
00207 [err, Info.TAXIS_FLOATS] = BrikInfo_SectionValue(BRIKinfo, 'TAXIS_FLOATS');
00208
00209 %TAXIS_OFFSETS
00210 [err, Info.TAXIS_OFFSETS] = BrikInfo_SectionValue(BRIKinfo, 'TAXIS_OFFSETS');
00211
00212 %IDCODE_STRING
00213 [err, Info.IDCODE_STRING] = BrikInfo_SectionValue(BRIKinfo, 'IDCODE_STRING');
00214
00215 %IDCODE_DATE
00216 [err, Info.IDCODE_DATE] = BrikInfo_SectionValue(BRIKinfo, 'IDCODE_DATE');
00217
00218 %BRICK_STATAUX
00219 [err, Info.BRICK_STATAUX] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_STATAUX');
00220
00221 %STAT_AUX
00222 [err, Info.STAT_AUX] = BrikInfo_SectionValue(BRIKinfo, 'STAT_AUX');
00223
00224 %HISTORY_NOTE
00225 [err, Info.HISTORY_NOTE] = BrikInfo_SectionValue(BRIKinfo, 'HISTORY_NOTE');
00226
00227 %NOTES_COUNT
00228 [err, Info.NOTES_COUNT] = BrikInfo_SectionValue(BRIKinfo, 'NOTES_COUNT');
00229
00230 %NOTE_NUMBER_001
00231 [err, Info.NOTE_NUMBER_001] = BrikInfo_SectionValue(BRIKinfo, 'NOTE_NUMBER_001');
00232
00233 %TAGALIGN_MATVEC
00234 [err, Info.TAGALIGN_MATVEC] = BrikInfo_SectionValue(BRIKinfo, 'TAGALIGN_MATVEC');
00235
00236 %VOLREG_CENTER_OLD
00237 [err, Info.VOLREG_CENTER_OLD] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_CENTER_OLD');
00238
00239 %VOLREG_CENTER_BASE
00240 [err, Info.VOLREG_CENTER_BASE] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_CENTER_BASE');
00241
00242 %VOLREG_ROTPARENT_IDCODE
00243 [err, Info.VOLREG_ROTPARENT_IDCODE] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_ROTPARENT_IDCODE');
00244
00245 %VOLREG_ROTPARENT_NAME
00246 [err, Info.VOLREG_ROTPARENT_NAME] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_ROTPARENT_NAME');
00247
00248 %VOLREG_GRIDPARENT_IDCODE
00249 [err, Info.VOLREG_GRIDPARENT_IDCODE] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_GRIDPARENT_IDCODE');
00250
00251 %VOLREG_GRIDPARENT_NAME
00252 [err, Info.VOLREG_GRIDPARENT_NAME] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_GRIDPARENT_NAME');
00253
00254 %VOLREG_INPUT_IDCODE
00255 [err, Info.VOLREG_INPUT_IDCODE] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_INPUT_IDCODE');
00256
00257 %VOLREG_INPUT_NAME
00258 [err, Info.VOLREG_INPUT_NAME] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_INPUT_NAME');
00259
00260 %VOLREG_BASE_IDCODE
00261 [err, Info.VOLREG_BASE_IDCODE] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_BASE_IDCODE');
00262
00263 %VOLREG_BASE_NAME
00264 [err, Info.VOLREG_BASE_NAME] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_BASE_NAME');
00265
00266 %VOLREG_ROTCOM_NUM
00267 [err, Info.VOLREG_ROTCOM_NUM] = BrikInfo_SectionValue(BRIKinfo, 'VOLREG_ROTCOM_NUM');
00268
00269 if (~err),
00270 for (i=1:1:Info.VOLREG_ROTCOM_NUM),
00271 sp = pad_strn(num2str(i-1), '0', 6, 1);
00272 spad = sprintf('[err, Info.VOLREG_MATVEC_%s] = BrikInfo_SectionValue(BRIKinfo, ''VOLREG_MATVEC_%s'');' , sp, sp);
00273 eval([ spad ]);
00274 spad = sprintf('[err, Info.VOLREG_ROTCOM_%s] = BrikInfo_SectionValue(BRIKinfo, ''VOLREG_ROTCOM_%s'');' , sp, sp);
00275 eval([ spad ]);
00276 end
00277 end
00278
00279
00280 %IDCODE_ANAT_PARENT
00281 [err, Info.IDCODE_ANAT_PARENT] = BrikInfo_SectionValue(BRIKinfo, 'IDCODE_ANAT_PARENT');
00282
00283 %TO3D_ZPAD
00284 [err, Info.TO3D_ZPAD] = BrikInfo_SectionValue(BRIKinfo, 'TO3D_ZPAD');
00285
00286 %IDCODE_WARP_PARENT
00287 [err, Info.IDCODE_WARP_PARENT] = BrikInfo_SectionValue(BRIKinfo, 'IDCODE_WARP_PARENT');
00288
00289 %WARP_TYPE
00290 [err, Info.WARP_TYPE] = BrikInfo_SectionValue(BRIKinfo, 'WARP_TYPE');
00291
00292 %WARP_DATA
00293 [err, Info.WARP_DATA] = BrikInfo_SectionValue(BRIKinfo, 'WARP_DATA');
00294
00295 %MARKS_XYZ
00296 [err, Info.MARKS_XYZ] = BrikInfo_SectionValue(BRIKinfo, 'MARKS_XYZ');
00297
00298 %MARKS_LAB
00299 [err, Info.MARKS_LAB] = BrikInfo_SectionValue(BRIKinfo, 'MARKS_LAB');
00300
00301 %MARKS_HELP
00302 [err, Info.MARKS_HELP] = BrikInfo_SectionValue(BRIKinfo, 'MARKS_HELP');
00303
00304 %MARKS_FLAGS
00305 [err, Info.MARKS_FLAGS] = BrikInfo_SectionValue(BRIKinfo, 'MARKS_FLAGS');
00306
00307 %TAGSET_NUM
00308 [err, Info.TAGSET_NUM] = BrikInfo_SectionValue(BRIKinfo, 'TAGSET_NUM');
00309
00310 %TAGSET_FLOATS
00311 [err, Info.TAGSET_FLOATS] = BrikInfo_SectionValue(BRIKinfo, 'TAGSET_FLOATS');
00312
00313 %TAGSET_LABELS
00314 [err, Info.TAGSET_LABELS] = BrikInfo_SectionValue(BRIKinfo, 'TAGSET_LABELS');
00315
00316 %LABEL_1
00317 [err, Info.LABEL_1] = BrikInfo_SectionValue(BRIKinfo, 'LABEL_1');
00318
00319 %LABEL_2
00320 [err, Info.LABEL_2] = BrikInfo_SectionValue(BRIKinfo, 'LABEL_2');
00321
00322 %DATASET_NAME
00323 [err, Info.DATASET_NAME] = BrikInfo_SectionValue(BRIKinfo, 'DATASET_NAME');
00324
00325 %DATASET_KEYWORDS
00326 [err, Info.DATASET_KEYWORDS] = BrikInfo_SectionValue(BRIKinfo, 'DATASET_KEYWORDS');
00327
00328 %BRICK_KEYWORDS
00329 [err, Info.BRICK_KEYWORDS] = BrikInfo_SectionValue(BRIKinfo, 'BRICK_KEYWORDS');
00330
00331 %HISTORY_NOTE
00332 %[err, Info.HISTORY_NOTE] = BrikInfo_SectionValue(BRIKinfo, 'HISTORY_NOTE');
00333
00334 %NOTES_COUNT
00335 %[err, Info.NOTES_COUNT] = BrikInfo_SectionValue(BRIKinfo, 'NOTES_COUNT');
00336
00337 if (~err),
00338 for (i=1:1:Info.NOTES_COUNT),
00339 sp = pad_strn(num2str(i), '0', 3, 1);
00340 spad = sprintf('[err, Info.NOTE_NUMBER_%s] = BrikInfo_SectionValue(BRIKinfo, ''NOTE_NUMBER_%s'');' , sp, sp);
00341 eval([ spad ]);
00342 end
00343 end
00344
00345 %SOMETHING
00346 %[err, Info.SOMETHING] = BrikInfo_SectionValue(BRIKinfo, 'SOMETHING');
00347
00348 %DOF
00349 [err, Info.WORSLEY_DF] = BrikInfo_SectionValue(BRIKinfo, 'WORSLEY_DF');
00350
00351 %NONJ
00352 [err, Info.WORSLEY_NCONJ] = BrikInfo_SectionValue(BRIKinfo, 'WORSLEY_NCONJ');
00353
00354 %FWHM
00355 [err, Info.WORSLEY_FWHM] = BrikInfo_SectionValue(BRIKinfo, 'WORSLEY_FWHM');
00356
00357 itype = unique(Info.BRICK_TYPES);
00358
00359 if (length(itype) > 1),
00360 Info.TypeName = 'Mutliple Types';
00361 else
00362 switch itype,
00363 case 0
00364 Info.TypeName = 'byte';
00365 Info.TypeBytes = 1;
00366 case 1
00367 Info.TypeName = 'short';
00368 Info.TypeBytes = 2; %Platform dependent
00369 case 2
00370 Info.TypeName = 'int';
00371 Info.TypeBytes = 4; %Platform dependent
00372 case 3
00373 Info.TypeName = 'float';
00374 Info.TypeBytes = 4; %Platform dependent
00375 otherwise
00376 Info.TypeName = 'Dunno';
00377 Info.TypeBytes = 0;
00378 end
00379 end
00380
00381 if (isempty(Info.BYTEORDER_STRING)), %field not found go native
00382 Info.ByteOrder = 'unspecified';
00383 else
00384 if (~isempty(strmatch('MSB_FIRST', Info.BYTEORDER_STRING))),
00385 Info.ByteOrder = 'ieee-be'; %Big Endian
00386 else
00387 if (~isempty(strmatch('LSB_FIRST', Info.BYTEORDER_STRING))),
00388 Info.ByteOrder = 'ieee-le'; %Little Endian
00389 else
00390 err = ErrEval(FuncName,'Err_Could not understand BYTEORDER_STRING');
00391 return;
00392 end
00393 end
00394 end
00395
00396 for (i=1:1:3),
00397 switch Info.ORIENT_SPECIFIC(i)
00398 case 0
00399 Info.Orientation(i,:) = 'RL'; %right to left
00400 case 1
00401 Info.Orientation(i,:) = 'LR';
00402 case 2
00403 Info.Orientation(i,:) = 'PA';
00404 case 3
00405 Info.Orientation(i,:) = 'AP';
00406 case 4
00407 Info.Orientation(i,:) = 'IS';
00408 case 5
00409 Info.Orientation(i,:) = 'SI';
00410 otherwise,
00411 err = ErrEval(FuncName,'Err_Cannot understand Orientation code');
00412 return;
00413 end
00414 end
00415
00416 Info.FileFormat = 'BRIK';
00417 Info.Extension_1D = '';
00418 err = 0;
00419 return;
00420