Home > . > prt_load.m

prt_load

PURPOSE ^

Function to load the PRT.mat and check its integrity regarding the

SYNOPSIS ^

function PRT = prt_load(fname,flag)

DESCRIPTION ^

 Function to load the PRT.mat and check its integrity regarding the 
 kernels and feature sets that it is supposed to contain. Updates the  set
 feature name if needed.

 input  : name of the PRT.mat, path included

 output : PRT structure updated
_______________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function PRT = prt_load(fname,flag)
0002 
0003 % Function to load the PRT.mat and check its integrity regarding the
0004 % kernels and feature sets that it is supposed to contain. Updates the  set
0005 % feature name if needed.
0006 %
0007 % input  : name of the PRT.mat, path included
0008 %
0009 % output : PRT structure updated
0010 %_______________________________________________________________________
0011 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0012 
0013 % Written by J. Schrouff
0014 % $Id$
0015 
0016 try
0017     load(fname)
0018 catch
0019     beep
0020     disp('Could not load file')
0021     PRT = [];
0022     return
0023 end
0024 
0025 if nargin<2
0026     flag = 0;
0027 end
0028 
0029 % get path
0030 prtdir = fileparts(fname);
0031 
0032 % for each feature set, check that the corresponding .dat is present in the
0033 % same directory and update the name of the file array if needed
0034 if isfield(PRT,'fas') && ~isempty(PRT.fas)
0035     ind = [];
0036     for i=1:length(PRT.fas)
0037         % get the name of the file array
0038         if ~isempty(PRT.fas(i).dat)
0039             fa_name=PRT.fas(i).dat.fname;
0040             if ~ispc
0041                 fname = strrep(fname,'\',filesep); 
0042             end 
0043             [fadir,fan,faext] = fileparts(fa_name);    
0044             if ~strcmpi(fadir,prtdir) % directories of PRT and feature set are different
0045                 if ~exist(fullfile(prtdir,[fan,faext]),'file')  % no feature set found
0046                     beep
0047                     disp(['No feature set named ',fan,' found in the PRT directory'])
0048                     disp('Information linked to that feature set is deleted')
0049                     disp('Computing the weights or using non-kernel methods using that feature set won''t be permitted')
0050                 else  % file exists but under the new directory
0051                     PRT.fas(i).dat.fname = fullfile(prtdir,[fan,faext]);
0052                     ind = [ind,i];
0053                 end
0054             else
0055                 ind = [ind,i];
0056             end
0057         elseif isempty(PRT.fas(i).dat) && ~isempty(PRT.fas(i).mod_name) %modality there in data and design, but not built in feature set
0058             ind = [ind,i];
0059         end
0060     end
0061     if isempty(ind)
0062         PRT = rmfield(PRT,'fas');
0063         PRT = rmfield(PRT,'fs');
0064     elseif length(ind)~=i
0065         % When a model comports the modality of the deleted fas, get rid of
0066         % the corresponding fs and model
0067         PRT.fas = PRT.fas(ind);
0068     end
0069 end
0070 
0071 %Check integrity of all PRT fields, for backward compatibility
0072 if flag==1
0073     [PRT,flag] = prt_struct(PRT,prtdir);
0074     if ~flag
0075         error('prt_load:EssentialFieldsMissing',['Essentials fields are missing. ',...
0076             'This PRT cannot be used. Data and Design should be started from scratch'])
0077     end
0078 end
0079 
0080 
0081 save([prtdir,filesep,'PRT.mat'],'PRT')

Generated on Tue 10-Feb-2015 18:16:33 by m2html © 2005