0001 function ok = write_label(lindex, lxyz, lvals, labelfile, subjid)
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 ok = 0;
0029
0030 if(nargin ~= 4 & nargin ~= 5)
0031 fprintf('ok = write_label(lindex, lxzy, lvals, labelfile, <subjid>)\n');
0032 return;
0033 end
0034
0035 if(exist('subjid') ~= 1) subjid = ''; end
0036
0037 if(isempty(lindex) & isempty(lxyz))
0038 fprintf('ERROR: both lindex and lxyz are empty.\n');
0039 return;
0040 end
0041
0042 if(~isempty(lindex) & ~isempty(lxyz))
0043 npoints1 = length(lindex);
0044 npoints2 = size(lxyz,1);
0045 if(npoints1 ~= npoints2)
0046 fprintf('ERROR: lindex and lxyz have different lengths.\n');
0047 return;
0048 end
0049 npoints = npoints1;
0050 elseif(~isempty(lindex))
0051 npoints = length(lindex);
0052 lxyz = zeros(npoints,3);
0053 elseif(~isempty(lxyz))
0054 npoints = length(lxyz);
0055 lindex = zeros(npoints,1);
0056 end
0057
0058 if(size(lxyz,2) ~= 3)
0059 fprintf('ERROR: lxyz does not have 3 columns\n');
0060 return;
0061 end
0062
0063 if(~isempty(lvals))
0064 if(npoints ~= length(lvals))
0065 fprintf('ERROR: length of lvals inconsistent\n');
0066 return;
0067 end
0068 else
0069 lvals = zeros(npoints,1);
0070 end
0071
0072
0073 fid = fopen(labelfile, 'w') ;
0074 if(fid == -1)
0075 fprintf('ERROR: could not open %s\n',labelfile);
0076 return;
0077 end
0078
0079 fprintf(fid,'#!ascii label, from subject %s \n',subjid);
0080 fprintf(fid,'%d\n',npoints);
0081
0082
0083 lindex = reshape(lindex,[npoints 1]);
0084 lxyz = reshape(lxyz,[npoints 3]);
0085 lvals = reshape(lvals,[npoints 1]);
0086
0087 l = [lindex lxyz lvals];
0088 fprintf(fid,'%d %f %f %f %f\n',l') ;
0089
0090 fclose(fid) ;
0091
0092 ok = 1;
0093
0094 return;