Home > fmri > utils > old > GE2SPM.orig > 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 2000

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

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