Unverified Commit 6a56fe91 authored by jayd1860's avatar jayd1860 Committed by GitHub
Browse files

Merge pull request #22 from BUNPC/procstream-to-script

Fixed display of automatically pruned/excluded channels, utility for exporting processing stream to script
parents 05e09985 18472ad3
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -106,18 +106,18 @@ hCh = zeros(length(lstML),1);
% Draw all channels
for ii = 1:length(lstML)
    hCh(ii) = line2(SD.SrcPos(ml(lstML(ii),1),:), SD.DetPos(ml(lstML(ii),2),:), [], gridsize);
    if     ismember(ii, lstIncl)
        % Draw included channel
        col = [1.00 1.00 1.00] * 0.85;
        lstyle = '-';
    if ismember(ii,lstExclAuto)
        % Draw auto-excluded channel
        col = [1.00 0.6 0.6];
        lstyle = '--';
    elseif ismember(ii, lstExclMan)
        % Draw manually excluded channel
        col = [1.00 1.00 1.00] * 0.85;
        lstyle = '--';
    elseif ismember(ii,lstExclAuto)
        % Draw auto-excluded channel
    elseif ismember(ii, lstIncl)
        % Draw included channel
        col = [1.00 1.00 1.00] * 0.85;
        lstyle = ':';
        lstyle = '-';
    end
    if ismember(ii, lstInvisible)
        lwidth = 1; 
@@ -145,7 +145,7 @@ if ~isempty(iSrcDet) && iSrcDet(1,1)~=0
        
        if ~isempty(iCh)
           
            if ~MeasListActMan(iCh2(idx))
            if ~MeasListActMan(iCh2(idx)) || ~MeasListActAuto(iCh2(idx))
                lstyle = '--'; 
            else
                lstyle = '-';
+3.58 KiB (86.3 KiB)

File changed.

No diff preview for this file type.

+10 −0
Original line number Diff line number Diff line
@@ -1713,3 +1713,13 @@ if isa(maingui.dataTree.currElem, 'RunClass')
else
    errordlg('Select a run to reset its excluded channels and time points.','No run selected');
end



% --------------------------------------------------------------------
function menuItemExportProcessingStreamScript_Callback(hObject, eventdata, handles)
global maingui
fname = uiputfile('*.m', 'Export Processing Stream to Script (.m)', 'processing_stream.m');
if fname ~= 0
    exportProcessScript(fname, maingui.dataTree.currElem.procStream);
end
+77 −0
Original line number Diff line number Diff line
function exportProcessScript(fname, procstream)
    if isa(procstream, 'ProcStreamClass')
        
        if length(procstream.fcalls) == 0
            return;
        end
        
        fid = fopen(fname, 'wt');
        
        if fid ~= -1
            
            inputs = {};
            
            % Write the header
            fprintf(fid, '%%{\n');
            fprintf(fid, 'The following input(s) to this processing stream must be defined:\n');
            for i = procstream.GetFcallsIdxs()
                argIn = procstream.GetInputArgs(i);
                for j = 1:length(argIn)
                    if ~any(strcmp(inputs, argIn{j}))
                        if ~exist(argIn{j},'var')
                            fprintf(fid, '%s\n', argIn{j});
                            inputs{end + 1} = argIn{j};
                        end
                    end
                end
            end
            fprintf(fid, '\n');
            fprintf(fid, 'A script which loads some inputs from an acquisition file (.snirf, .nirs) at acquisition_path\n');
            fprintf(fid, 'is provided below. Consult the Homer3 wiki https://github.com/BUNPC/Homer3/wiki on the\n');
            fprintf(fid, 'specified format of other function inputs.\n');
          
            fprintf(fid, '%%}\n');
        
            fprintf(fid, '\n');
            fprintf(fid, 'acquired_path = '''';\n');
            fprintf(fid, '\n');
            fprintf(fid, 'if ~isempty(acquired_path)\n');
            fprintf(fid, '    acquired = SnirfClass(acquired_path);\n');
            for i = 1:length(inputs)
               fprintf(fid, '    %s = acquired.%s;\n', inputs{i}, inputs{i});
            end
            fprintf(fid, 'end\n');
            fprintf(fid, '\n');
            
            % Write the processing stream
            for i = procstream.GetFcallsIdxs()
                argIn = procstream.GetInputArgs(i);
                for j = 1:length(argIn)
                    if ~exist(argIn{j},'var')
                        eval(sprintf('%s = procstream.input.GetVar(''%s'');', argIn{j}, argIn{j}));
                    end
                end
                [sargin, p, sarginVal] = procstream.ParseInputParams(i);
                sargout = procstream.ParseOutputArgs(i);
                
                fprintf(fid, '%%{\n');
                fprintf(fid, procstream.fcalls(i).help);
                fprintf(fid, '%%}');
                
                fprintf(fid, '\n');
                fprintf(fid, '%s = %s%s%s);\n', sargout, procstream.GetFuncCallName(i), procstream.fcalls(i).argIn.str, sarginVal);
                fprintf(fid, '\n');
            end
            
            fprintf(fid, '\n');
            fclose(fid);
            
        else
            return;
        end
        
    else
       return; 
    end
    
end
 No newline at end of file