Home > data-access > record_additional_variable.m

record_additional_variable

PURPOSE ^

Records the given data under the given subject and name.

SYNOPSIS ^

function [ filename ] = record_additional_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_additional_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 a core variable, cannot overwrite', variable_name);
0019     fprintf('=========================\n');
0020     return;
0021 end
0022 
0023 filename = get_variable_path(subject_id, variable_name);
0024 
0025 if isempty(getenv('IU_username'))
0026     IU_username = input('enter IU username: ', 's');
0027     setenv('IU_username', IU_username);
0028 end
0029 
0030 sdata.variable = variable_name;
0031 sdata.data = data;
0032 sdata.info.stack = get_stack();
0033 sdata.info.timestamp = datestr(now);
0034 sdata.info.subject = subject_id;
0035 sdata.info.path = filename;
0036 sdata.info.hostname = getenv('computername');
0037 sdata.info.user = getenv('IU_username');
0038 
0039 record_variable_log(sdata);
0040 
0041 save(filename, 'sdata');
0042 fprintf('Saved variable "%s" for subject %d\n', variable_name, subject_id);
0043 
0044 end
0045 
0046 
0047 
0048 function stack = get_stack()
0049 try
0050     error('Caught');
0051 catch ME
0052     stack = ME.stack(2:end); % don't show get_stack() on the list
0053 end
0054 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005