Home > functions > internal > dsDownloadFiles.m

dsDownloadFiles

PURPOSE ^

dsDownloadFiles - Downloads data from the web (utility function)

SYNOPSIS ^

function destinationFile = dsDownloadFiles(requestedFile,destinationFile,overwrite_flag,verbose_flag)

DESCRIPTION ^

dsDownloadFiles - Downloads data from the web (utility function)

 Purpose: Downloads large files (mostly demo data) from branch dsFiles in
 the DynaSim git repo.

 Usage:
   destinationFile = dsDownloadFiles(requestedFile,destinationFile,overwrite_flag,verbose_flag)

 Inputs:
   requestedFile: String containing the name and path of the
                  requested file in the dsFiles DynaSim branch
   destinationFile: Destination for the requested file on the local
   filesystem. If left empty, then it mirrors the location requestedFile.
   overwrite_flag: {0,1} - Flag to force overwrite if directory already
       exists.
   verbose_flag: {0,1} - verbose flag

 Outputs:
   destinationFile:  Destination path for the requested file.

 Examples:
 
 Author:
   David Stanley, stanleyd@bu.edu, August 2017

 See also: dsUnzipDemoData, dsZipDemoData, demos_generate_data.m (demo script)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function destinationFile = dsDownloadFiles(requestedFile,destinationFile,overwrite_flag,verbose_flag)
0002 %dsDownloadFiles - Downloads data from the web (utility function)
0003 %
0004 % Purpose: Downloads large files (mostly demo data) from branch dsFiles in
0005 % the DynaSim git repo.
0006 %
0007 % Usage:
0008 %   destinationFile = dsDownloadFiles(requestedFile,destinationFile,overwrite_flag,verbose_flag)
0009 %
0010 % Inputs:
0011 %   requestedFile: String containing the name and path of the
0012 %                  requested file in the dsFiles DynaSim branch
0013 %   destinationFile: Destination for the requested file on the local
0014 %   filesystem. If left empty, then it mirrors the location requestedFile.
0015 %   overwrite_flag: {0,1} - Flag to force overwrite if directory already
0016 %       exists.
0017 %   verbose_flag: {0,1} - verbose flag
0018 %
0019 % Outputs:
0020 %   destinationFile:  Destination path for the requested file.
0021 %
0022 % Examples:
0023 %
0024 % Author:
0025 %   David Stanley, stanleyd@bu.edu, August 2017
0026 %
0027 % See also: dsUnzipDemoData, dsZipDemoData, demos_generate_data.m (demo script)
0028 
0029     
0030     if nargin < 2
0031         destinationFile = [];
0032     end
0033     
0034     if nargin < 3
0035         overwrite_flag = 0;
0036     end
0037     
0038     if nargin < 4
0039         verbose_flag = 1;
0040     end
0041     
0042     
0043     if isempty(destinationFile)
0044         destinationFile = requestedFile;
0045     end
0046     
0047     % Remove anything before DynaSim, so we're using relative path
0048     ind = strfind(lower(requestedFile),'dynasim');
0049     if ~isempty(ind)
0050         requestedFileRelative = requestedFile(ind+8:end);
0051     else
0052         requestedFileRelative = requestedFile;
0053     end
0054     
0055     % Create destination folder if missing
0056     [pathstr, name, ext] = fileparts(destinationFile);
0057     if ~exist(pathstr,'dir');
0058         if verbose_flag; fprintf('Creating folder: %s\n', pathstr); end
0059         mkdirSilent(pathstr);
0060     end
0061 
0062     requestedURL = ['https://github.com/DynaSim/DynaSimFiles/blob/master/' requestedFileRelative '?raw=true'];
0063     if ispc
0064         % If it's a windows machine, replace all \ with / in URL path.
0065         requestedURL = strrep(requestedURL,'\','/');
0066     end
0067     
0068     if verbose_flag; fprintf('Downloading file from: %s ... ',requestedURL); end
0069     try
0070         out = websave(destinationFile,requestedURL);
0071     catch
0072         error('Requested file not found!');
0073     end
0074     if verbose_flag; fprintf('done.\n');
0075         fprintf('Saving to: %s\n',destinationFile); end
0076     
0077     
0078 end

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