Home > fmri > utils > GE2SPM > GE_writeSPMHeader.m

GE_writeSPMHeader

PURPOSE ^

SYNOPSIS ^

function status = GE_writeSPMHeader(fname,header)

DESCRIPTION ^

 status = GE_writeSPMHeader(fname,header)

 Write SPM header into fname.hdr

 Souheil J. Inati
 Dartmouth College
 May 2000
 souheil.inati@dartmouth.edu

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = GE_writeSPMHeader(fname,header)
0002 %
0003 % status = GE_writeSPMHeader(fname,header)
0004 %
0005 % Write SPM header into fname.hdr
0006 %
0007 % Souheil J. Inati
0008 % Dartmouth College
0009 % May 2000
0010 % souheil.inati@dartmouth.edu
0011 %
0012 
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 %                           %
0015 % Write Analyze header file %
0016 %                           %
0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0018 [fid,message] = fopen(fname,'w');
0019 
0020 if (fid == -1)
0021     disp(message);
0022     return;
0023 end
0024 
0025 % write ANALYZE Header Key
0026 %---------------------------------------------------------------------------
0027 fseek(fid,0,'bof');
0028 fwrite(fid,header.sizeOfHeader,        'uint32');
0029 fwrite(fid,header.dataType,            'char' );
0030 fwrite(fid,header.dbName,        'char');
0031 fwrite(fid,header.extents,        'int32');
0032 fwrite(fid,header.sessionError,        'int16' );
0033 fwrite(fid,header.regular,        'char' );
0034 fwrite(fid,header.hkeyUnused,        'char' );
0035 
0036 % write ANALYZE Image Dimension
0037 %---------------------------------------------------------------------------
0038 fseek(fid,40,'bof');
0039 fwrite(fid,header.dim,            'int16');
0040 fwrite(fid,header.voxUnits,        'char' );
0041 fwrite(fid,header.calUnits,        'char' );
0042 fwrite(fid,header.iUnused1,        'int16' );
0043 fwrite(fid,header.datatype,        'int16' );
0044 fwrite(fid,header.bitpix,        'int16');
0045 fwrite(fid,header.dimUnused,        'int16');
0046 fwrite(fid,header.pixDim,        'float32');
0047 fwrite(fid,header.voxOffset,        'float32');
0048 fwrite(fid,header.fUnused1,        'float32');
0049 fwrite(fid,header.fUnused2,        'float32');
0050 fwrite(fid,header.fUnused3,        'float32');
0051 fwrite(fid,header.calMax,        'float32');
0052 fwrite(fid,header.calMin,        'float32');
0053 fwrite(fid,header.compressed,        'float32');
0054 fwrite(fid,header.verified,        'float32');
0055 fwrite(fid,header.glMax,        'int32');
0056 fwrite(fid,header.glMin,        'int32');
0057 
0058 % write ANALYZE data history
0059 %---------------------------------------------------------------------------
0060 fwrite(fid,header.description,    'char');
0061 fwrite(fid,header.auxFile,    'char');
0062 fwrite(fid,header.orient,    'int8');
0063 fwrite(fid,header.originator,    'int16');
0064 fwrite(fid,header.generated,    'char');
0065 fwrite(fid,header.scanNum,    'char');
0066 fwrite(fid,header.patientID,    'char');
0067 fwrite(fid,header.expDate,    'char');
0068 fwrite(fid,header.expTime,    'char');
0069 fwrite(fid,header.histUN0,    'char');
0070 fwrite(fid,header.views,    'int32');
0071 fwrite(fid,header.volsAdded,    'int32');
0072 fwrite(fid,header.startField,    'int32');
0073 fwrite(fid,header.fieldSkip,    'int32');
0074 fwrite(fid,header.oMax,        'int32');
0075 fwrite(fid,header.oMin,        'int32');
0076 fwrite(fid,header.sMax,        'int32');
0077 
0078 if fwrite(fid,header.sMin,    'int32') ~= 1
0079     fclose(fid);
0080     error(['Error writing ' fname '. Check your disk space.']);
0081 end
0082 
0083 if ftell(fid) ~= -1
0084   status = 1;
0085 else
0086   status = 0;
0087 end
0088 
0089 fclose(fid);
0090 
0091 return
0092 
0093 
0094 
0095 
0096 
0097

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003