Home > functions > internal > dsExportData.m

dsExportData

PURPOSE ^

EXPORTDATA - export DynaSim data structure in various formats.

SYNOPSIS ^

function dsExportData(data,varargin)

DESCRIPTION ^

EXPORTDATA - export DynaSim data structure in various formats.

 Usage:
   dsExportData(data,varargin)

 Inputs:
   - data: DynaSim data structure (see dsCheckData)
   - options:
     'filename'    : name of output data file (default: 'data.mat')
     'format'      : mat. todo: csv, HDF. (default: 'mat')
     'verbose_flag': whether to print log info (default: 0)

 See also: dsImport, dsCheckData, dsSimulate

 Author: Jason Sherfey, PhD <jssherfey@gmail.com>
 Copyright (C) 2016 Jason Sherfey, Boston University, USA

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dsExportData(data,varargin)
0002 %EXPORTDATA - export DynaSim data structure in various formats.
0003 %
0004 % Usage:
0005 %   dsExportData(data,varargin)
0006 %
0007 % Inputs:
0008 %   - data: DynaSim data structure (see dsCheckData)
0009 %   - options:
0010 %     'filename'    : name of output data file (default: 'data.mat')
0011 %     'format'      : mat. todo: csv, HDF. (default: 'mat')
0012 %     'verbose_flag': whether to print log info (default: 0)
0013 %
0014 % See also: dsImport, dsCheckData, dsSimulate
0015 %
0016 % Author: Jason Sherfey, PhD <jssherfey@gmail.com>
0017 % Copyright (C) 2016 Jason Sherfey, Boston University, USA
0018 
0019 options=dsCheckOptions(varargin,{...
0020   'filename','data.mat',[],... % name of output data file
0021   'format','mat',[],... % mat. todo: csv, HDF
0022   'matCompatibility_flag',1,{0,1},... % whether to save mat files in compatible mode, or to prioritize > 2GB VARs
0023   'verbose_flag',0,{0,1},... % whether to print log info
0024   },false);
0025 
0026 switch lower(options.format)
0027   case 'mat'
0028     if numel(data)==1
0029       % split DynaSim data structure into separate variables saved to a
0030       % mat-file for subsequent loading with matfile()
0031       vars=fieldnames(data);
0032       for i=1:length(vars)
0033         eval(sprintf('%s=data.%s;',vars{i},vars{i}));
0034       end
0035       if options.matCompatibility_flag
0036         try
0037           save(options.filename,vars{:},'-v7');
0038         catch
0039           fprintf('Data is not ''-v7'' compatible. Setting ''matCompatibility_flag'' to 0.\n')
0040           options.matCompatibility_flag = 0;
0041           if strcmp(reportUI,'matlab')
0042             save(options.filename,vars{:},'-v7.3');
0043           else
0044             save(options.filename,vars{:},'-hdf5'); % hdf5 format in Octave
0045           end
0046         end
0047       else
0048         if strcmp(reportUI,'matlab')
0049           save(options.filename,vars{:},'-v7.3');
0050         else
0051           save(options.filename,vars{:},'-hdf5'); % hdf5 format in Octave
0052         end
0053       end
0054     else
0055       if options.matCompatibility_flag
0056         try
0057           save(options.filename,'data','-v7');
0058         catch
0059           fprintf('Data is not ''-v7'' compatible. Setting ''matCompatibility_flag'' to 0.\n')
0060           options.matCompatibility_flag = 0;
0061           if strcmp(reportUI,'matlab')
0062             save(options.filename,'data','-v7.3');
0063           else
0064             save(options.filename,'data','-hdf5'); % hdf5 format in Octave
0065           end
0066         end
0067       else
0068         if strcmp(reportUI,'matlab')
0069           save(options.filename,'data','-v7.3');
0070         else
0071           save(options.filename,'data','-hdf5'); % hdf5 format in Octave
0072         end
0073       end
0074     end
0075   case 'csv'
0076     % write csv file
0077     % ExportCSV(data,options.filename);
0078   case 'hdf'
0079     % ExportHDF(data,options.filename);
0080   otherwise
0081     % not recognized
0082 end
0083 
0084 if options.verbose_flag
0085   fprintf('\tData saved to %s\n',options.filename);
0086 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005