Home > vbmeg > functions > tool_box > dmri_processor > functions > util > write_label.m

write_label

PURPOSE ^

ok = write_label(lindex, lxzy, lvals, labelfile, <subjid>)

SYNOPSIS ^

function ok = write_label(lindex, lxyz, lvals, labelfile, subjid)

DESCRIPTION ^

 ok = write_label(lindex, lxzy, lvals, labelfile, <subjid>)

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ok = write_label(lindex, lxyz, lvals, labelfile, subjid)
0002 % ok = write_label(lindex, lxzy, lvals, labelfile, <subjid>)
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 
0008 %
0009 % write_label.m
0010 %
0011 % Original Author: Doug Greve
0012 % CVS Revision Info:
0013 %    $Author: nicks $
0014 %    $Date: 2011/03/02 00:04:13 $
0015 %    $Revision: 1.4 $
0016 %
0017 % Copyright 2011 The General Hospital Corporation (Boston, MA) "MGH"
0018 %
0019 % Terms and conditions for use, reproduction, distribution and contribution
0020 % are found in the 'FreeSurfer Software License Agreement' contained
0021 % in the file 'LICENSE' found in the FreeSurfer distribution, and here:
0022 %
0023 % https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
0024 %
0025 % Reporting: freesurfer@nmr.mgh.harvard.edu
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 % 2012/04/27 M.Fukushima 'subid'->'subjid'
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 % open as an ascii file
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 % Make sure they are npoints by 1 %
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;

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