0001 function fiff_write_double_complex_matrix(fid,kind,mat)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 me='MNE:fiff_write_double_complex_matrix';
0024
0025 if nargin ~= 3
0026 error(me,'Incorrect number of arguments');
0027 end
0028
0029 FIFFT_COMPLEX_DOUBLE = 21;
0030 FIFFT_MATRIX = bitshift(1,30);
0031 FIFFT_MATRIX_COMPLEX_DOUBLE = bitor(FIFFT_COMPLEX_DOUBLE,FIFFT_MATRIX);
0032 FIFFV_NEXT_SEQ=0;
0033
0034 datasize = 2*8*numel(mat) + 4*3;
0035
0036 count = fwrite(fid,int32(kind),'int32');
0037 if count ~= 1
0038 error(me,'write failed');
0039 end
0040 count = fwrite(fid,int32(FIFFT_MATRIX_COMPLEX_DOUBLE),'int32');
0041 if count ~= 1
0042 error(me,'write failed');
0043 end
0044 count = fwrite(fid,int32(datasize),'int32');
0045 if count ~= 1
0046 error(me,'write failed');
0047 end
0048 count = fwrite(fid,int32(FIFFV_NEXT_SEQ),'int32');
0049 if count ~= 1
0050 error(me,'write failed');
0051 end
0052 nrow = size(mat,1);
0053 ncol = size(mat,2);
0054 for j = 1:nrow
0055 for k = 1:ncol
0056 count = fwrite(fid,real(mat(j,k)),'double');
0057 if count ~= 1
0058 error(me,'write failed');
0059 end
0060 count = fwrite(fid,imag(mat(j,k)),'double');
0061 if count ~= 1
0062 error(me,'write failed');
0063 end
0064 end
0065 end
0066 dims(1) = size(mat,2);
0067 dims(2) = size(mat,1);
0068 dims(3) = 2;
0069 count = fwrite(fid,int32(dims),'int32');
0070 if count ~= 3
0071 error(me,'write failed');
0072 end
0073
0074 return;
0075