0001 function p = get_contrib_data( contrib , file )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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
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
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
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) = [];
0082 isdir = cell2mat({d.isdir});
0083 ls = {d.name};
0084 ls = ls(isdir)';
0085 else
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 'human-ventilation-2014'
0102 'if-experimental-lung-injury'
0103 'if-neonate-spontaneous'
0104 'if-neonate-ventilated'
0105 'if-peep-acute-lung-injury'
0106 'jn_chest_phantom'
0107 'yg-ventilation-colourmap'
0108 };
0109 end
0110
0111 end