classdef SCD
 % main interface class for interacting with SCD expcodes
 %
 % H = SCD.load(expcode);  % loads the obj for a desired expcode
 % H = SCD.init(expcode);  % loads and initialize
 % H = SCD.prepforcompile(expcode);  % loads, initialize, and setup (ready for compilation)
 % H = SCD.prepforsim(expcode,shot); % does load, init, setup, actualize
 %
 % C = SCD.getexpcodecontainer; % get expcode container
 
 methods (Static)
  function H=load(expcode)
    % Creating the experimental code container class
    SCDexps = SCD.getexpcodecontainer();
    H = SCDexps.getbymaincode(expcode);
    SCDconf_setConf('SIM'); % set conf for simulation
  end
  
  function H=init(expcode)
    H=SCD.load(expcode);
    H.init;
  end
  
  function H=prepforcompile(expcode)
    H = SCD.load(expcode);
    H.init;
    H.setup;
  end
  
  function H=prepforsim(expcode,shot)
    fprintf('\n### EXPCODE LOAD PHASE ###\n');
    H=SCD.load(expcode);
    fprintf('\n### EXPCODE INIT PHASE ###\n');  
    H.init;
    fprintf('\n### EXPCODE SETUP PHASE ###\n');      
    H.setup;
    fprintf('\n### EXPCODE ACTUALIZE PHASE ###\n');
    H.actualize(shot);
  end
  
  function help()
   help(mfilename);
  end
  
  function list()
   SCD.help;
  end
 
  function clean_dd()
    % Close all data open dictionaries
    fprintf('Closing all data dictionaries and discarding changes')
    Simulink.data.dictionary.closeAll('-discard');
    % Cleans unversioned data dictionaries
    fprintf('Cleaning unversioned data dictionaries for clean test\n')
    system('git clean -xf *.sldd');  % clean local sldd
    system('git submodule foreach --quiet ''git clean -fx *.sldd'''); % clean submodules too
  end
  
  function SCDexps = getexpcodecontainer()
   SCDexps = SCDconf_createexpcodes;
  end
 end
end