Code to identify data folders

From Mslice
Revision as of 11:40, 31 March 2011 by Alex Buts (talk | contribs) (Created page with " <syntaxhighlight lang="MATLAB M"> if isfield(msl_conf,field) % this is a path which may be specified either in the file % itself, or in config...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


<syntaxhighlight lang="MATLAB M">

      if isfield(msl_conf,field) 
           % this is a path which may be specified either in the file
           % itself, or in configuration; Arbitration would occur. 
           if (strcmp(field,'MspDir')||strcmp(field,'MspFile')) % if it is MspDir or MspFile, then it has been set already
               if strcmp(field,'MspFile') && ~strcmp(value,file_name) % but the msp file name in defined in the file is different from the filename itself
                   % need to fix it;
                     nmodific =nmodific+1;
                     modificators{nmodific}='MspFile';
                     nmodific =nmodific+1;
                     modificators{nmodific}=file_name;                    
               end      
           elseif strncmp(value,'$.',2) % this is probably relative path to a sample data and the field is read only
              full_dir=fullfile(get(mslice_config,'MspDir'),value(4:length(value)));
              set(mslice_config,field,full_dir);               
              is_read_only=true;
           elseif strncmp(value,'.',1) % this is probably relative path to a sample data below
              full_dir=fullfile(get(mslice_config,'MspDir'),value(3:length(value)));
              if exist(full_dir,'dir')
                   set(mslice_config,field,full_dir);
              else
                  full_dir=get(mslice_config,field);
                  msp_dir =get(mslice_config,'MspDir');
                  short_dir=strrep(full_dir,msp_dir,'./');
                  nmodific =nmodific+1;
                  modificators{nmodific}=field;
                  nmodific =nmodific+1;
                  modificators{nmodific}=short_dir;                
              end
           else
               if exist(value,'dir') % the path is specified by sting in the file;
                   set(mslice_config,field,value);
               else % the path should be y specified by config variables
                  path=get(mslice_config,field);
                  msp_dir =get(mslice_config,'MspDir');
                  path  =strrep(path,msp_dir,'./');
                 
                  nmodific =nmodific+1;
                  modificators{nmodific}=field;
                  nmodific =nmodific+1;
                  modificators{nmodific}=path;
               end
                 
           end         
         % replace sting in old msp file with its new equivalents
         if ~isempty(modificators)&&(~is_read_only)
         for i=1:floor(nmodific/2)
            perl('set_key_value.pl',fullname,modificators{2*i-1},modificators{2*i});       
         end
     end
            

</syntaxhighlight>