Home > vbmeg > external > mne > fiff_start_writing_raw.m

fiff_start_writing_raw

PURPOSE ^

SYNOPSIS ^

function [fid,cals] = fiff_start_writing_raw(name,info,sel)

DESCRIPTION ^

 function [fid,cals] = fiff_start_writing_raw(name,info,sel)

 name       filename
 info       The measurement info block of the source file
 sel        Which channels will be included in the output file (optional)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fid,cals] = fiff_start_writing_raw(name,info,sel)
0002 %
0003 % function [fid,cals] = fiff_start_writing_raw(name,info,sel)
0004 %
0005 % name       filename
0006 % info       The measurement info block of the source file
0007 % sel        Which channels will be included in the output file (optional)
0008 %
0009 
0010 %
0011 %   Author : Matti Hamalainen, MGH Martinos Center
0012 %   License : BSD 3-clause
0013 %
0014 % Revision 1.6  2009/03/31 01:12:30  msh
0015 % Improved ID handling
0016 %
0017 % Revision 1.5  2009/03/30 11:37:37  msh
0018 % Added copying of measurement info blocks from the original like in mne_browse_raw
0019 %
0020 % Revision 1.4  2008/05/06 20:40:56  msh
0021 % Fixed ordering of output for compatibility with maxfilter averager
0022 %
0023 % Revision 1.3  2008/04/16 22:24:57  msh
0024 % Added megacq parameters to the measurement info
0025 %
0026 % Revision 1.2  2008/03/13 19:18:06  msh
0027 % Read and write FIFF_MEAS_DATE from/to FIFFB_MEAS_INFO as appropriate
0028 %
0029 % Revision 1.1  2007/11/07 16:05:05  msh
0030 % New routines for writing raw files
0031 %
0032 
0033 me='MNE:fiff_start_writing_raw';
0034 if nargin ~= 2 && nargin ~= 3
0035     error(me,'Incorrect number of arguments');
0036 end
0037 %
0038 global FIFF;
0039 if isempty(FIFF)
0040     FIFF = fiff_define_constants();
0041 end
0042 %
0043 %   We will always write floats
0044 %
0045 data_type = 4;
0046 if nargin == 2
0047     sel = 1:info.nchan;
0048 end
0049 chs = info.chs(sel);
0050 nchan = length(chs);
0051 %
0052 %  Create the file and save the essentials
0053 %
0054 fid = fiff_start_file(name);
0055 fiff_start_block(fid,FIFF.FIFFB_MEAS);
0056 fiff_write_id(fid,FIFF.FIFF_BLOCK_ID);
0057 if ~isempty(info.meas_id)
0058     fiff_write_id(fid,FIFF.FIFF_PARENT_BLOCK_ID,info.meas_id);
0059 end
0060 %
0061 %
0062 %    Measurement info
0063 %
0064 fiff_start_block(fid,FIFF.FIFFB_MEAS_INFO);
0065 %
0066 %    Blocks from the original
0067 %
0068 blocks = [ FIFF.FIFFB_SUBJECT FIFF.FIFFB_HPI_MEAS FIFF.FIFFB_HPI_RESULT FIFF.FIFFB_ISOTRAK FIFF.FIFFB_PROCESSING_HISTORY ];
0069 have_hpi_result = false;
0070 have_isotrak    = false;
0071 if length(blocks) > 0 && isfield(info,'filename') && ~isempty(info.filename)
0072     [ fid2, tree ] = fiff_open(info.filename);
0073     for k = 1:length(blocks)
0074         nodes = fiff_dir_tree_find(tree,blocks(k));
0075         fiff_copy_tree(fid2,tree.id,nodes,fid);
0076         if blocks(k) == FIFF.FIFFB_HPI_RESULT && length(nodes) > 0
0077             have_hpi_result = true;
0078         end
0079         if blocks(k) == FIFF.FIFFB_ISOTRAK && length(nodes) > 0
0080             have_isotrak = true;
0081         end
0082     end
0083     fclose(fid2);
0084 end
0085 %
0086 %    megacq parameters
0087 %
0088 if ~isempty(info.acq_pars) || ~isempty(info.acq_stim)
0089     fiff_start_block(fid,FIFF.FIFFB_DACQ_PARS);
0090     if ~isempty(info.acq_pars)
0091         fiff_write_string(fid,FIFF.FIFF_DACQ_PARS, ...
0092             info.acq_pars);
0093     end
0094     if ~isempty(info.acq_stim)
0095         fiff_write_string(fid,FIFF.FIFF_DACQ_STIM, ...
0096             info.acq_stim);
0097     end
0098     fiff_end_block(fid,FIFF.FIFFB_DACQ_PARS);
0099 end
0100 %
0101 %    Coordinate transformations if the HPI result block was not there
0102 %
0103 if ~have_hpi_result
0104     if ~isempty(info.dev_head_t)
0105         fiff_write_coord_trans(fid,info.dev_head_t);
0106     end
0107     if ~isempty(info.ctf_head_t)
0108         fiff_write_coord_trans(fid,info.ctf_head_t);
0109     end
0110 end
0111 %
0112 %    Polhemus data
0113 %
0114 if ~isempty(info.dig) && ~have_isotrak
0115     fiff_start_block(fid,FIFF.FIFFB_ISOTRAK);
0116     for k = 1:length(info.dig)
0117         fiff_write_dig_point(fid,info.dig(k))
0118     end
0119     fiff_end_block(fid,FIFF.FIFFB_ISOTRAK);
0120 end
0121 %
0122 %    Projectors
0123 %
0124 fiff_write_proj(fid,info.projs);
0125 %
0126 %    CTF compensation info
0127 %
0128 fiff_write_ctf_comp(fid,info.comps);
0129 %
0130 %    Bad channels
0131 %
0132 if length(info.bads) > 0
0133     fiff_start_block(fid,FIFF.FIFFB_MNE_BAD_CHANNELS);
0134     fiff_write_name_list(fid,FIFF.FIFF_MNE_CH_NAME_LIST,info.bads);
0135     fiff_end_block(fid,FIFF.FIFFB_MNE_BAD_CHANNELS);
0136 end
0137 %
0138 %    General
0139 %
0140 fiff_write_float(fid,FIFF.FIFF_SFREQ,info.sfreq);
0141 fiff_write_float(fid,FIFF.FIFF_HIGHPASS,info.highpass);
0142 fiff_write_float(fid,FIFF.FIFF_LOWPASS,info.lowpass);
0143 fiff_write_int(fid,FIFF.FIFF_NCHAN,nchan);
0144 fiff_write_int(fid,FIFF.FIFF_DATA_PACK,data_type);
0145 if [ ~isempty(info.meas_date) ]
0146     fiff_write_int(fid,FIFF.FIFF_MEAS_DATE,info.meas_date);
0147 end
0148 %
0149 %    Channel info
0150 %
0151 for k = 1:nchan
0152     %
0153     %   Scan numbers may have been messed up
0154     %
0155     chs(k).scanno = k;
0156     chs(k).range  = 1.0;
0157     cals(k) = chs(k).cal;
0158     fiff_write_ch_info(fid,chs(k));
0159 end
0160 %
0161 %
0162 fiff_end_block(fid,FIFF.FIFFB_MEAS_INFO);
0163 %
0164 % Start the raw data
0165 %
0166 fiff_start_block(fid,FIFF.FIFFB_RAW_DATA);
0167 
0168 return;

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