Home > vbmeg > external > mne > fiff_write_id.m

fiff_write_id

PURPOSE ^

SYNOPSIS ^

function fiff_write_id(fid,kind,id)

DESCRIPTION ^

 fiff_write_id(fid,kind,id)
 
 Writes fiff id 

     fid           An open fif file descriptor
     kind          The tag kind
     id            The id to write

 If the id argument is missing it will be generated here

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fiff_write_id(fid,kind,id)
0002 %
0003 % fiff_write_id(fid,kind,id)
0004 %
0005 % Writes fiff id
0006 %
0007 %     fid           An open fif file descriptor
0008 %     kind          The tag kind
0009 %     id            The id to write
0010 %
0011 % If the id argument is missing it will be generated here
0012 %
0013 
0014 %
0015 %   Author : Matti Hamalainen, MGH Martinos Center
0016 %   License : BSD 3-clause
0017 %
0018 %   Revision 1.6  2009/03/30 11:37:37  msh
0019 %   Added copying of measurement info blocks from the original like in mne_browse_raw
0020 %
0021 %   Revision 1.5  2008/06/16 17:27:11  msh
0022 %   Incremented file version number to 1.2
0023 %
0024 %   Revision 1.4  2006/04/23 15:29:40  msh
0025 %   Added MGH to the copyright
0026 %
0027 %   Revision 1.3  2006/04/14 11:03:57  msh
0028 %   Changed fiff_write_id write a given id.
0029 %   Added parent id writing.
0030 %
0031 %   Revision 1.2  2006/04/10 23:26:54  msh
0032 %   Added fiff reading routines
0033 %
0034 %   Revision 1.1  2005/12/05 16:01:04  msh
0035 %   Added an initial set of fiff writing routines.
0036 %
0037 %
0038 me='MNE:fiff_write_id';
0039 
0040 if nargin == 2
0041    timezone=5;                              %   Matlab does not know the timezone
0042    id.version   = bitor(bitshift(1,16),2);  %   Version (1 << 16) | 2
0043    id.machid(1) = 65536*rand(1);            %   Machine id is random for now
0044    id.machid(2) = 65536*rand(1);            %   Machine id is random for now
0045    id.secs      = 3600*(24*(now-datenum(1970,1,1,0,0,0))+timezone);
0046    id.usecs     = 0;                        %   Do not know how we could get this
0047 elseif nargin ~= 3
0048    error(me,'Incorrect number of arguments');
0049 end
0050 
0051 FIFFT_ID_STRUCT=31;
0052 FIFFV_NEXT_SEQ=0;
0053 %
0054 %
0055 datasize=5*4;                       %   The id comprises five integers
0056 count = fwrite(fid,int32(kind),'int32');
0057 if count ~= 1
0058     error(me,'write failed');
0059 end
0060 count = fwrite(fid,int32(FIFFT_ID_STRUCT),'int32');
0061 if count ~= 1
0062     error(me,'write failed');
0063 end
0064 count = fwrite(fid,int32(datasize),'int32');
0065 if count ~= 1
0066     error(me,'write failed');
0067 end
0068 count = fwrite(fid,int32(FIFFV_NEXT_SEQ),'int32');
0069 if count ~= 1
0070    error(me,'write failed');
0071 end
0072 %
0073 % Collect the bits together for one write
0074 %
0075 data(1) = id.version;
0076 data(2) = id.machid(1);
0077 data(3) = id.machid(2);
0078 data(4) = id.secs;
0079 data(5) = id.usecs;
0080 count = fwrite(fid,int32(data),'int32');
0081 if count ~= 5
0082     error(me,'write failed');
0083 end
0084 return;
0085

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005