0001 function stim_st = ensemble_export_stims(data_st,params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 params.mysql.conn_id = mysql_make_conn(mysql_login(params));
0014 conn_id = params.mysql.conn_id;
0015
0016
0017
0018 if ~isempty(data_st) && ismember(data_st.vars,'stimulus_id')
0019 cols = set_var_col_const(data_st.vars);
0020 stimids = unique(data_st.data{cols.stimulus_id});
0021 else
0022 srchFlds = {'expname','experiment_name','experiment_title'};
0023 expNameMask = isfield(params.ensemble,srchFlds);
0024 if ~any(expNameMask)
0025 error('Cannot locate experiment name in params structure');
0026 else
0027 experiment_names = params.ensemble.(srchFlds{find(expNameMask,1,'first')});
0028 end
0029
0030 if ~iscell(experiment_names)
0031 experiment_names = {experiment_names};
0032 end
0033
0034 nexp = length(experiment_names);
0035 stimids = [];
0036 for iexp = 1:nexp
0037 experiment_title = experiment_names{iexp};
0038
0039
0040 mysql_str = sprintf(['SELECT experiment_id, response_table FROM experiment WHERE ' ...
0041 'experiment_title = "%s";'], experiment_title);
0042 [expID, respTable] = mysql(conn_id, mysql_str);
0043
0044
0045
0046 mysql_str = sprintf(['SELECT DISTINCT stimulus_id FROM %s ' ...
0047 'WHERE experiment_id = %d AND stimulus_id IS NOT NULL;'], respTable{1}, expID);
0048 stimids = union(stimids, mysql(conn_id, mysql_str));
0049 end
0050 end
0051
0052
0053 fprintf('Retrieving information for %d stimuli\n', length(stimids));
0054 stim_st = ensemble_get_stiminfo(struct('vars','stimulus_id','data',{{stimids}}),params);
0055 scols = set_var_col_const(stim_st.vars);
0056
0057
0058 params.funcName = 'ensemble_copy_stimulus';
0059 params.funcParams.stimroot = params.ensemble.stimroot;
0060 params.funcParams.outpath = params.paths.stimpath;
0061
0062 stim_st = stim_st.data{scols.stimulus_metadata};
0063 fprintf('Processing stimuli with function: %s\n', params.funcName);
0064 ensemble_processStims(stim_st,params);
0065
0066 return
0067 end