xxsimWriteLogToCsv

PURPOSE ^

xxsimWriteLogToCsv - writes logged variables to a comma separated value (csv) file.

SYNOPSIS ^

function [retval] = xxsimWriteLogToCsv(logFileName, logVariables)

DESCRIPTION ^

 xxsimWriteLogToCsv - writes logged variables to a comma separated value (csv) file.

 Syntax: 
   retval = xxsimWriteLogToCsv(logFileName, logVariables)  
 
 Inputs:
   logFileName  = name of csv file e.g 'parametersList.csv'.
   logVariables = list of variables e.g {'time', 'LogVarTest.v1'}.
                  Note: make sure the variable name exists in active model.
                        If not, an error message will be returned.

 Outputs: 
   retval = returns true if all arguments are valid, false otherwise.

 Examples:
    xxsimWriteLogToCsv('Example.csv','time');
        Write the log variable time to Example.csv.
        Note: time should be set as log variable before simulation, by using
        xxsimSetLogVariables.
    xxsimWriteLogToCsv('Example.csv',{'time','Position.x'});
        Write the log variables time and Position.x to Example.csv.
        Note: time and Position.x should be set as log variable before 
        simulation, by using xxsimSetLogVariables.

 See also: xxsimSetLogVariables

 Author: Controllab Products B.V.
 email: info@controllab.nl
 Website: http://www.controllab.nl
 September 2013

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [retval] = xxsimWriteLogToCsv(logFileName, logVariables)
0002 % xxsimWriteLogToCsv - writes logged variables to a comma separated value (csv) file.
0003 %
0004 % Syntax:
0005 %   retval = xxsimWriteLogToCsv(logFileName, logVariables)
0006 %
0007 % Inputs:
0008 %   logFileName  = name of csv file e.g 'parametersList.csv'.
0009 %   logVariables = list of variables e.g {'time', 'LogVarTest.v1'}.
0010 %                  Note: make sure the variable name exists in active model.
0011 %                        If not, an error message will be returned.
0012 %
0013 % Outputs:
0014 %   retval = returns true if all arguments are valid, false otherwise.
0015 %
0016 % Examples:
0017 %    xxsimWriteLogToCsv('Example.csv','time');
0018 %        Write the log variable time to Example.csv.
0019 %        Note: time should be set as log variable before simulation, by using
0020 %        xxsimSetLogVariables.
0021 %    xxsimWriteLogToCsv('Example.csv',{'time','Position.x'});
0022 %        Write the log variables time and Position.x to Example.csv.
0023 %        Note: time and Position.x should be set as log variable before
0024 %        simulation, by using xxsimSetLogVariables.
0025 %
0026 % See also: xxsimSetLogVariables
0027 %
0028 % Author: Controllab Products B.V.
0029 % email: info@controllab.nl
0030 % Website: http://www.controllab.nl
0031 % September 2013
0032 
0033 %------------- BEGIN CODE --------------
0034     retval = false;
0035     
0036     %check if the model file exists
0037     if ~exist(logFileName, 'file')
0038         %create an empty file in order to retrieve the absolute file path
0039         fid = fopen(logFileName, 'w');
0040         fclose(fid);
0041     end    
0042     
0043     [status, result, msgid] = fileattrib(logFileName);
0044     if status == 1 
0045     
0046         % use the full resolved name, and we're done
0047         useFilename = result.Name;
0048     else
0049     
0050         % check if the user provided a full name
0051         [directory, name, extension, version] = fileparts(logFileName);
0052     
0053         % is an extension given?
0054         if length(extension) == 0 
0055             extension = '.csv';
0056         end
0057         
0058         % is a directory given?
0059         if length(directory) == 0
0060             % use the current directory
0061             directory = pwd;
0062         end
0063         
0064         useFilename = fullfile(directory, cstrcat(name, extension));
0065     end
0066 
0067     retval = xrlinvoke('xxsim.simulator.writeLogToCsv', struct('name', useFilename, 'variables', {{ logVariables, 'array' }} , 'overwrite', logical(1) )  );
0068     if ( retval == false )
0069         error('could not write log to csv-file');
0070     end
0071 end
0072 %------------- END OF CODE --------------

Generated on Sun 10-Dec-2017 19:24:51