Home > vbmeg > external > mne > fiff_write_ch_info.m

fiff_write_ch_info

PURPOSE ^

SYNOPSIS ^

function fiff_write_ch_info(fid,ch)

DESCRIPTION ^

 fiff_write_ch_info(fid,ch)

 Writes a channel information record to a fif file

     fid           An open fif file descriptor
     ch            The channel information structure to write

     The type, cal, unit, and pos members are explained in Table 9.5
     of the MNE manual

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fiff_write_ch_info(fid,ch)
0002 %
0003 % fiff_write_ch_info(fid,ch)
0004 %
0005 % Writes a channel information record to a fif file
0006 %
0007 %     fid           An open fif file descriptor
0008 %     ch            The channel information structure to write
0009 %
0010 %     The type, cal, unit, and pos members are explained in Table 9.5
0011 %     of the MNE manual
0012 %
0013 
0014 %
0015 %
0016 %   Author : Matti Hamalainen, MGH Martinos Center
0017 %   License : BSD 3-clause
0018 %
0019 %   Revision 1.6  2006/04/23 15:29:40  msh
0020 %   Added MGH to the copyright
0021 %
0022 %   Revision 1.5  2006/04/18 20:44:46  msh
0023 %   Added reading of forward solution.
0024 %   Use length instead of size when appropriate
0025 %
0026 %   Revision 1.4  2006/04/13 17:47:50  msh
0027 %   Make coil coordinate transformation or EEG electrode location out of the channel  info.
0028 %
0029 %   Revision 1.3  2006/04/12 10:29:02  msh
0030 %   Made evoked data writing compatible with the structures returned in reading.
0031 %
0032 %   Revision 1.2  2006/04/10 23:26:54  msh
0033 %   Added fiff reading routines
0034 %
0035 %   Revision 1.1  2005/12/05 16:01:04  msh
0036 %   Added an initial set of fiff writing routines.
0037 %
0038 %
0039 
0040 me='MNE:fiff_write_ch_info';
0041 
0042 if nargin ~= 2
0043     error(me,'Incorrect number of arguments');
0044 end
0045 
0046 FIFF_CH_INFO=203;
0047 FIFFT_CH_INFO_STRUCT=30;
0048 FIFFV_NEXT_SEQ=0;
0049 
0050 %typedef struct _fiffChPosRec {
0051 %  fiff_int_t   coil_type;          /*!< What kind of coil. */
0052 %  fiff_float_t r0[3];              /*!< Coil coordinate system origin */
0053 %  fiff_float_t ex[3];              /*!< Coil coordinate system x-axis unit vector */
0054 %  fiff_float_t ey[3];              /*!< Coil coordinate system y-axis unit vector */
0055 %  fiff_float_t ez[3];             /*!< Coil coordinate system z-axis unit vector */
0056 %} fiffChPosRec,*fiffChPos;        /*!< Measurement channel position and coil type */
0057 
0058 
0059 %typedef struct _fiffChInfoRec {
0060 %  fiff_int_t    scanNo;        /*!< Scanning order # */
0061 %  fiff_int_t    logNo;         /*!< Logical channel # */
0062 %  fiff_int_t    kind;          /*!< Kind of channel */
0063 %  fiff_float_t  range;         /*!< Voltmeter range (only applies to raw data ) */
0064 %  fiff_float_t  cal;           /*!< Calibration from volts to... */
0065 %  fiff_ch_pos_t chpos;         /*!< Channel location */
0066 %  fiff_int_t    unit;          /*!< Unit of measurement */
0067 %  fiff_int_t    unit_mul;      /*!< Unit multiplier exponent */
0068 %  fiff_char_t   ch_name[16];   /*!< Descriptive name for the channel */
0069 %} fiffChInfoRec,*fiffChInfo;   /*!< Description of one channel */
0070 
0071 datasize=4*13 + 4*7 + 16;
0072 count = fwrite(fid,int32(FIFF_CH_INFO),'int32');
0073 if count ~= 1
0074     error(me,'write failed');
0075 end
0076 count = fwrite(fid,int32(FIFFT_CH_INFO_STRUCT),'int32');
0077 if count ~= 1
0078     error(me,'write failed');
0079 end
0080 count = fwrite(fid,int32(datasize),'int32');
0081 if count ~= 1
0082     error(me,'write failed');
0083 end
0084 count = fwrite(fid,int32(FIFFV_NEXT_SEQ),'int32');
0085 if count ~= 1
0086     error(me,'write failed');
0087 end
0088 %
0089 %   Start writing fiffChInfoRec
0090 %
0091 count = fwrite(fid,int32(ch.scanno),'int32');
0092 if count ~= 1
0093     error(me,'write failed');
0094 end
0095 count = fwrite(fid,int32(ch.logno),'int32');
0096 if count ~= 1
0097     error(me,'write failed');
0098 end
0099 count = fwrite(fid,int32(ch.kind),'int32');
0100 if count ~= 1
0101     error(me,'write failed');
0102 end
0103 count = fwrite(fid,single(ch.range),'single');
0104 if count ~= 1
0105     error(me,'write failed');
0106 end
0107 count = fwrite(fid,single(ch.cal),'single');
0108 if count ~= 1
0109     error(me,'write failed');
0110 end
0111 %
0112 %   fiffChPosRec follows
0113 %
0114 count = fwrite(fid,int32(ch.coil_type),'int32');
0115 if count ~= 1
0116     error(me,'write failed');
0117 end
0118 count = fwrite(fid,single(ch.loc),'single');
0119 if count ~= 12
0120     error(me,'write failed');
0121 end
0122 %
0123 %   unit and unit multiplier
0124 %
0125 count = fwrite(fid,int32(ch.unit),'int32');
0126 if count ~= 1
0127     error(me,'write failed');
0128 end
0129 count = fwrite(fid,int32(ch.unit_mul),'int32');
0130 if count ~= 1
0131     error(me,'write failed');
0132 end
0133 %
0134 %   Finally channel name
0135 %
0136 len=length(ch.ch_name);
0137 if len > 15
0138     ch_name = ch.ch_name(1:15);
0139 else
0140     ch_name = ch.ch_name;
0141 end
0142 len = length(ch_name);
0143 count = fwrite(fid,ch_name,'char');
0144 if count ~= len
0145     error(me,'write failed');
0146 end
0147 if len < 16
0148     dum=zeros(1,16-len);
0149     count = fwrite(fid,uint8(dum),'uchar');
0150     if count ~= 16-len
0151         error(me,'write failed');
0152     end
0153 end
0154 return;

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