0001 function mne_write_inverse_sol_w(stem,inv,sol)
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
0033 me='MNE:mne_write_inverse_sol_w';
0034 global FIFF;
0035 if isempty(FIFF)
0036 FIFF = fiff_define_constants();
0037 end
0038
0039 if nargin ~= 3
0040 error(me,'Incorrect number of arguments');
0041 end
0042
0043 if length(sol) ~= inv.nsource
0044 error(me,'The solution data cannot correspond to these source spaces');
0045 end
0046
0047 off = 0;
0048 for k = 1:length(inv.src)
0049 off = off + inv.src(k).nuse;
0050 if (inv.src(k).id ~= FIFF.FIFFV_MNE_SURF_LEFT_HEMI && ...
0051 inv.src(k).id ~= FIFF.FIFFV_MNE_SURF_RIGHT_HEMI)
0052 error(me,'Source space hemispheres not properly assigned.');
0053 end
0054 end
0055 if off ~= inv.nsource
0056 error(me,'The source spaces are inconsistent with other inverse/forward operator data');
0057 end
0058
0059
0060
0061 off = 0;
0062 for k = 1:length(inv.src)
0063 if (inv.src(k).id == FIFF.FIFFV_MNE_SURF_LEFT_HEMI)
0064 outname = sprintf('%s-lh.w',stem);
0065 elseif (inv.src(k).id == FIFF.FIFFV_MNE_SURF_RIGHT_HEMI)
0066 outname = sprintf('%s-rh.w',stem);
0067 end
0068 w.vertices = double(inv.src(k).vertno - 1);
0069 w.data = sol(off+1:off+inv.src(k).nuse);
0070 mne_write_w_file(outname,w);
0071 off = off + inv.src(k).nuse;
0072 fprintf(1,'Wrote %s\n',outname);
0073 end
0074
0075 return;
0076
0077
0078