Home > vbmeg > external > mne > fiff_write_evoked.m

fiff_write_evoked

PURPOSE ^

SYNOPSIS ^

function fiff_write_evoked(name,data)

DESCRIPTION ^

 function fiff_write_evoked(name,data)

 name     filename
 data     the data structure returned from fiff_read_evoked

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fiff_write_evoked(name,data)
0002 %
0003 % function fiff_write_evoked(name,data)
0004 %
0005 % name     filename
0006 % data     the data structure returned from fiff_read_evoked
0007 %
0008 %
0009 
0010 %
0011 %   Author : Matti Hamalainen, MGH Martinos Center
0012 %   License : BSD 3-clause
0013 %
0014 % Revision 1.14  2009/03/31 01:12:30  msh
0015 % Improved ID handling
0016 %
0017 % Revision 1.13  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.12  2008/03/13 19:18:07  msh
0021 % Read and write FIFF_MEAS_DATE from/to FIFFB_MEAS_INFO as appropriate
0022 %
0023 % Revision 1.11  2006/10/04 20:12:37  msh
0024 % Added fiff_read_evoked_all
0025 % Modified fiff_pick_channels_evoked to handle multiple data sets
0026 % Added bad channel writing to fiff_write_evoked
0027 %
0028 % Revision 1.10  2006/09/26 23:20:23  msh
0029 % Moved block ID and parent block id to the meas block.
0030 %
0031 % Revision 1.9  2006/06/14 05:32:43  msh
0032 % Added missing FIFF_NAVE to each aspect written.
0033 %
0034 % Revision 1.8  2006/05/29 16:57:32  msh
0035 % Make sure that scan numbers are correct.
0036 %
0037 % Revision 1.7  2006/04/23 15:29:40  msh
0038 % Added MGH to the copyright
0039 %
0040 % Revision 1.6  2006/04/18 20:44:46  msh
0041 % Added reading of forward solution.
0042 % Use length instead of size when appropriate
0043 %
0044 % Revision 1.5  2006/04/14 15:49:49  msh
0045 % Improved the channel selection code and added ch_names to measurement info.
0046 %
0047 % Revision 1.4  2006/04/14 11:03:57  msh
0048 % Changed fiff_write_id write a given id.
0049 % Added parent id writing.
0050 %
0051 % Revision 1.3  2006/04/13 23:09:46  msh
0052 % Further streamlining of the coordinate transformations.
0053 %
0054 % Revision 1.2  2006/04/12 13:13:51  msh
0055 % Added fiff_find_evoked.m
0056 % Use aspect_kind field name instead of aspect_type
0057 %
0058 % Revision 1.1  2006/04/12 10:29:02  msh
0059 % Made evoked data writing compatible with the structures returned in reading.
0060 %
0061 %
0062 me='MNE:fiff_write_evoked';
0063 if nargin ~= 2
0064     error(me,'File name and data required as an arguments');
0065 end
0066 %
0067 global FIFF;
0068 if isempty(FIFF)
0069     FIFF = fiff_define_constants();
0070 end
0071 %
0072 %  Create the file and save the essentials
0073 %
0074 fid = fiff_start_file(name);
0075 fiff_start_block(fid,FIFF.FIFFB_MEAS);
0076 fiff_write_id(fid,FIFF.FIFF_BLOCK_ID);
0077 if ~isempty(data.info.meas_id)
0078     fiff_write_id(fid,FIFF.FIFF_PARENT_BLOCK_ID,data.info.meas_id);
0079 end
0080 %
0081 %    Measurement info
0082 %
0083 fiff_start_block(fid,FIFF.FIFFB_MEAS_INFO);
0084 %
0085 %    Blocks from the original
0086 %
0087 blocks = [ FIFF.FIFFB_SUBJECT FIFF.FIFFB_HPI_MEAS FIFF.FIFFB_HPI_RESULT FIFF.FIFFB_ISOTRAK FIFF.FIFFB_PROCESSING_HISTORY ];
0088 have_hpi_result = false;
0089 have_isotrak    = false;
0090 if length(blocks) > 0 && isfield(data.info,'filename') && ~isempty(data.info.filename)
0091     [ fid2, tree ] = fiff_open(data.info.filename);
0092     for k = 1:length(blocks)
0093         nodes = fiff_dir_tree_find(tree,blocks(k));
0094         fiff_copy_tree(fid2,tree.id,nodes,fid);
0095         if blocks(k) == FIFF.FIFFB_HPI_RESULT && length(nodes) > 0
0096             have_hpi_result = true;
0097         end
0098         if blocks(k) == FIFF.FIFFB_ISOTRAK && length(nodes) > 0
0099             have_isotrak = true;
0100         end
0101     end
0102     fclose(fid2);
0103 end
0104 %
0105 %    General
0106 %
0107 fiff_write_float(fid,FIFF.FIFF_SFREQ,data.info.sfreq);
0108 fiff_write_float(fid,FIFF.FIFF_HIGHPASS,data.info.highpass);
0109 fiff_write_float(fid,FIFF.FIFF_LOWPASS,data.info.lowpass);
0110 fiff_write_int(fid,FIFF.FIFF_NCHAN,data.info.nchan);
0111 if [ ~isempty(data.info.meas_date) ]
0112     fiff_write_int(fid,FIFF.FIFF_MEAS_DATE,data.info.meas_date);
0113 end
0114 %
0115 %    Coordinate transformations if the HPI result block was not there
0116 %
0117 if ~have_hpi_result
0118     if ~isempty(data.info.dev_head_t)
0119         fiff_write_coord_trans(fid,data.info.dev_head_t);
0120     end
0121     if ~isempty(data.info.ctf_head_t)
0122         fiff_write_coord_trans(fid,data.info.ctf_head_t);
0123     end
0124 end
0125 %
0126 %  Channel information
0127 %
0128 for k = 1:data.info.nchan
0129     %
0130     %   Scan numbers may have been messed up
0131     %
0132     data.info.chs(k).scanno = k;
0133     fiff_write_ch_info(fid,data.info.chs(k));
0134 end
0135 %
0136 %    Polhemus data
0137 %
0138 if ~isempty(data.info.dig) && ~have_isotrak
0139     fiff_start_block(fid,FIFF.FIFFB_ISOTRAK);
0140     for k = 1:length(data.info.dig)
0141         fiff_write_dig_point(fid,data.info.dig(k))
0142     end
0143     fiff_end_block(fid,FIFF.FIFFB_ISOTRAK);
0144 end
0145 %
0146 %    Projectors
0147 %
0148 fiff_write_proj(fid,data.info.projs);
0149 %
0150 %    CTF compensation info
0151 %
0152 fiff_write_ctf_comp(fid,data.info.comps);
0153 %
0154 %    Bad channels
0155 %
0156 if length(data.info.bads) > 0
0157     fiff_start_block(fid,FIFF.FIFFB_MNE_BAD_CHANNELS);
0158     fiff_write_name_list(fid,FIFF.FIFF_MNE_CH_NAME_LIST,data.info.bads);
0159     fiff_end_block(fid,FIFF.FIFFB_MNE_BAD_CHANNELS);
0160 end
0161 %
0162 %
0163 fiff_end_block(fid,FIFF.FIFFB_MEAS_INFO);
0164 %
0165 % One or more evoked data sets
0166 %
0167 fiff_start_block(fid,FIFF.FIFFB_PROCESSED_DATA);
0168 for set = 1:length(data.evoked)
0169     fiff_start_block(fid,FIFF.FIFFB_EVOKED);
0170     %
0171     % Comment is optional
0172     %
0173     if size(data.evoked(set).comment,2) > 0
0174         fiff_write_string(fid,FIFF.FIFF_COMMENT,data.evoked(set).comment);
0175     end
0176     %
0177     % First and last sample
0178     %
0179     fiff_write_int(fid,FIFF.FIFF_FIRST_SAMPLE,data.evoked(set).first);
0180     fiff_write_int(fid,FIFF.FIFF_LAST_SAMPLE,data.evoked(set).last);
0181     %
0182     % The epoch itself
0183     %
0184     fiff_start_block(fid,FIFF.FIFFB_ASPECT);
0185     %
0186     fiff_write_int(fid,FIFF.FIFF_ASPECT_KIND, ...
0187         data.evoked(set).aspect_kind);
0188     fiff_write_int(fid,FIFF.FIFF_NAVE,data.evoked(set).nave);
0189     decal = zeros(data.info.nchan,data.info.nchan);
0190     for k = 1:data.info.nchan
0191         decal(k,k) = 1.0/(data.info.chs(k).cal);
0192     end
0193     fiff_write_float_matrix(fid,FIFF.FIFF_EPOCH,decal*data.evoked(set).epochs);
0194     %
0195     fiff_end_block(fid,FIFF.FIFFB_ASPECT);
0196     %
0197     fiff_end_block(fid,FIFF.FIFFB_EVOKED);
0198 end
0199 fiff_end_block(fid,FIFF.FIFFB_PROCESSED_DATA);
0200 
0201 fiff_end_block(fid,FIFF.FIFFB_MEAS);
0202 
0203 fiff_end_file(fid);
0204 return;

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