Home > data-access > record_variable.m

record_variable

PURPOSE ^

Records the given data under the given subject and name.

SYNOPSIS ^

function [ filename ] = record_variable( subject_id, variable_name, data )

DESCRIPTION ^

Records the given data under the given subject and name.
   record_variable(SUBJECT_ID, VARIABLE_NAME, DATA)

   Finds the filename that the data should be recorded in, using
   get_variable_path.  Then, creates the little structure that goes in
   that file, and records the data there using MATLAB's SAVE function.

   If the given variable name does not have documentation, for now the
   function will complain, but eventually the data will not be saved in
   the requested place, but instead will be put in a temporary directory.

   The return value is the filename where the data was saved.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ filename ] = record_variable( subject_id, variable_name, data )
0002 %Records the given data under the given subject and name.
0003 %   record_variable(SUBJECT_ID, VARIABLE_NAME, DATA)
0004 %
0005 %   Finds the filename that the data should be recorded in, using
0006 %   get_variable_path.  Then, creates the little structure that goes in
0007 %   that file, and records the data there using MATLAB's SAVE function.
0008 %
0009 %   If the given variable name does not have documentation, for now the
0010 %   function will complain, but eventually the data will not be saved in
0011 %   the requested place, but instead will be put in a temporary directory.
0012 %
0013 %   The return value is the filename where the data was saved.
0014 %
0015 
0016 if ~is_core_variable(variable_name)
0017     fprintf('====== NOT SAVED ========\n');
0018     warning('%s is not a core variable, please use record_additional_variable instead. Or, have Chen add this variable to core_variable_list.txt', variable_name);
0019     fprintf('=========================\n');
0020     return;
0021 end
0022 
0023 filename = get_variable_path(subject_id, variable_name);
0024 
0025 request_IU_username();
0026 
0027 user = getenv('IU_username');
0028 if ~is_core_member(user)
0029     fprintf('\n====== NOT SAVED ========\n');
0030     warning('%s is not an authorized member, please contact Chen', user);
0031     fprintf('===========================\n');
0032     return;
0033 end
0034 
0035 sdata.variable = variable_name;
0036 sdata.data = data;
0037 sdata.info.stack = get_stack();
0038 sdata.info.timestamp = datestr(now);
0039 sdata.info.subject = subject_id;
0040 sdata.info.path = filename;
0041 sdata.info.hostname = getenv('computername');
0042 sdata.info.user = getenv('IU_username');
0043 
0044 save(filename, 'sdata');
0045 fprintf('Saved variable "%s" for subject %d\n', variable_name, subject_id);
0046 
0047 end
0048 
0049 
0050 
0051 function stack = get_stack()
0052 try
0053     error('Caught');
0054 catch ME
0055     stack = ME.stack(2:end); % don't show get_stack() on the list
0056 end
0057 end
0058

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005