get_contrib_data

PURPOSE ^

GET_CONTRIB_DATA Get files from the EIDORS data_contrib repository

SYNOPSIS ^

function p = get_contrib_data( contrib , file )

DESCRIPTION ^

GET_CONTRIB_DATA Get files from the EIDORS data_contrib repository
   GET_CONTRIB_DATA(CONTRIB, FILE) returns the path to the FILE from
   directory CONTRIB.

   GOT_CONTRIB_DATA('list') lists the valid contributions

   If the file in question is not found locally, GET_CONTRIB_DATA offers
   the option to download it to the current directory.

 See also: WEBSAVE

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function p = get_contrib_data( contrib , file )
0002 %GET_CONTRIB_DATA Get files from the EIDORS data_contrib repository
0003 %   GET_CONTRIB_DATA(CONTRIB, FILE) returns the path to the FILE from
0004 %   directory CONTRIB.
0005 %
0006 %   GOT_CONTRIB_DATA('list') lists the valid contributions
0007 %
0008 %   If the file in question is not found locally, GET_CONTRIB_DATA offers
0009 %   the option to download it to the current directory.
0010 %
0011 % See also: WEBSAVE
0012 
0013 % (C) 2016 Bartlomiej Grychtol. License: GPL version 2 or version 3
0014 % $Id: get_contrib_data.m 5424 2017-04-25 17:45:19Z aadler $
0015 
0016 % check for data_contrib
0017 have_local_data = exist(get_local_path,'dir');
0018 
0019 if nargin>0 && ischar(contrib) && strcmp(contrib,'list')
0020    disp(list_directories);
0021 end
0022 
0023 
0024 ls = list_directories(have_local_data);
0025 
0026 if ~ismember(contrib,ls)
0027    error('Unknown contribution %s.',contrib);
0028 end
0029 
0030 if have_local_data
0031    p = [get_local_path filesep contrib filesep file];
0032    if ~exist(p, 'file')
0033       fprintf('File %s not found.\n',p);
0034       p = download_file(contrib,file,[get_local_path filesep contrib]);
0035    end
0036 else % attempt to get from the web
0037    fprintf('The requested file %s is absent and needs to be downloaded from the web\n',file);
0038    p = download_file(contrib,file,cd);
0039 end
0040 end
0041 
0042 function p=download_file(contrib,file,path)
0043    p = [get_remote_address '/' contrib '/' file];
0044    while 1
0045       s = input('Try to download now? Y/N [Y]','s');
0046       if isempty(s), s='Y'; end
0047       switch s
0048          case {'n','N'}
0049             fprintf('The file can be obtained from <a href="%s">%s</a>\n',p,p);
0050             break
0051          case {'y','Y'}
0052             try
0053                p = websave([path filesep file],p);
0054             catch
0055                fprintf('Download of <a href="%s">%s</a> failed!\n',p,p);
0056                try delete([path filesep file '.html']); end % cleanup
0057                p = [];
0058             end
0059             break
0060          otherwise
0061             fprintf('Response not understood\n');
0062       end
0063    end
0064 end
0065 
0066 function p = get_local_path
0067    % where am i
0068    p = fileparts(mfilename('fullpath'));
0069    p = strrep(p,['eidors' filesep 'interface'],'');
0070    p = [p 'htdocs' filesep 'data_contrib'];
0071 end
0072 
0073 function p = get_remote_address
0074    p = 'http://eidors.org/data_contrib';
0075 end
0076 
0077 function ls = list_directories(have_local_data)
0078    if nargin==0, have_local_data=false; end
0079    if have_local_data
0080       d = dir(get_local_path);
0081       d(1:2) = []; % . and ..
0082       isdir = cell2mat({d.isdir});
0083       ls = {d.name};
0084       ls = ls(isdir)';
0085    else % static list
0086       ls = {'Dargaville-ICM2010'
0087          'ab_2d_thorax_model'
0088          'at-head-mesh'
0089          'at-thorax-mesh'
0090          'bb-human-arm'
0091          'cg-2012-ards-recruitment'
0092          'cg_deforming_tank_phantom'
0093          'cg_normal_breathing_2006'
0094          'chb_child_acute_lung_injury'
0095          'chb_hfov_porcine'
0096          'db_backproj_matrix'
0097          'dg_geophysical_EIT'
0098          'ds_tank_phantom'
0099          'evaluation-phantom'
0100          'gh_pleural_cavity'
0101          'if-experimental-lung-injury'
0102          'if-neonate-spontaneous'
0103          'if-peep-acute-lung-injury'
0104          'jn_chest_phantom'
0105          'yg-ventilation-colourmap'
0106          };
0107    end
0108 
0109 end

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005