0001 function mne_write_inverse_sol_stc(stem,inv,sol,tmin,tstep)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 me='MNE:mne_write_inverse_sol_stc';
0033 global FIFF;
0034 if isempty(FIFF)
0035 FIFF = fiff_define_constants();
0036 end
0037
0038 if nargin ~= 5
0039 error(me,'Incorrect number of arguments');
0040 end
0041
0042 if size(sol,1) ~= inv.nsource
0043 error(me,'The solution matrix cannot correspond to these source spaces');
0044 end
0045
0046 off = 0;
0047 for k = 1:length(inv.src)
0048 off = off + inv.src(k).nuse;
0049 if (inv.src(k).id ~= FIFF.FIFFV_MNE_SURF_LEFT_HEMI && ...
0050 inv.src(k).id ~= FIFF.FIFFV_MNE_SURF_RIGHT_HEMI)
0051 error(me,'Source space hemispheres not properly assigned.');
0052 end
0053 end
0054 if off ~= inv.nsource
0055 error(me,'The source spaces are inconsistent with other inverse/forward operator data');
0056 end
0057
0058
0059
0060 off = 0;
0061 for k = 1:length(inv.src)
0062 if (inv.src(k).id == FIFF.FIFFV_MNE_SURF_LEFT_HEMI)
0063 outname = sprintf('%s-lh.stc',stem);
0064 elseif (inv.src(k).id == FIFF.FIFFV_MNE_SURF_RIGHT_HEMI)
0065 outname = sprintf('%s-rh.stc',stem);
0066 end
0067 stc.tmin = tmin;
0068 stc.tstep = tstep;
0069 stc.vertices = inv.src(k).vertno - 1;
0070 stc.data = sol(off+1:off+inv.src(k).nuse,:);
0071 mne_write_stc_file(outname,stc);
0072 off = off + inv.src(k).nuse;
0073 fprintf(1,'Wrote %s\n',outname);
0074 end
0075
0076 return;
0077
0078
0079