1+ function [collection ,message ] = get_old_collection(collection_id ,username ,password )
2+ % Gets the given collection from the birg website using the given username
3+ % and password. If called without any of the parameters, displays dialogs
4+ % to get them from the user.
5+ %
6+ % Returns the collection or {} on error. If there is an error, message
7+ % contains an error message for the user.
8+ message = [];
9+
10+ if ~exist(' username' ,' var' ) || ~exist(' password' ,' var' )
11+ [username ,password ] = logindlg ;
12+ if isempty(username ) && isempty(password )
13+ collection = {};
14+ message = ' You must enter a username and password' ;
15+ return ;
16+ end
17+ end
18+
19+ if ~exist(' collection_id' ,' var' ) || isempty(collection_id )
20+ prompt= {' Collection ID:' };
21+ name= ' Enter the collection ID from the website' ;
22+ numlines= 1 ;
23+ defaultanswer= {' ' };
24+ answer= inputdlg(prompt ,name ,numlines ,defaultanswer );
25+ if isempty(answer )
26+ message = ' You must enter a collection ID' ;
27+ collection = {};
28+ return ;
29+ end
30+ collection_id = str2double(answer{1 });
31+ if isnan(collection_id ) || length(collection_id ) ~= 1
32+ message = ' You must enter a number as the collection ID' ;
33+ collection = {};
34+ return ;
35+ end
36+ end
37+
38+ url = sprintf(' http://birg.cs.wright.edu/omics_analysis/collections/%d .xml' ,collection_id );
39+ try
40+ if exist(' proxy.conf' ,' file' )
41+ load_proxy(' proxy.conf' );
42+ end
43+ % [xml, urlstatus] = webread(url, 'name', username, 'password', password);
44+ [xml ,urlstatus ] = urlread(url , ' Timeout' , 360 , ' get' ,{' name' ,username ,' password' ,password });
45+ if ~isempty(regexp(xml ,' password' , ' once' ))
46+ message = ' Invalid password' ;
47+ collection = {};
48+ return ;
49+ end
50+ if urlstatus == 0
51+ error(' urlread failed with status 0: %s ' ,url ); % #ok<SPERR>
52+ end
53+ catch ME
54+ disp(urlstatus );
55+ throw(ME );
56+ end
57+ n = regexp(xml ,' <data>(.*)</data>' ,' tokens' );
58+ data = n{1 }{1 };
59+ % file = tempname;
60+ % fid = fopen(file,'w');
61+ % fwrite(fid,xml);
62+ % %fprintf(fid,xml);
63+ % fclose(fid);
64+ % collection_xml = xml2struct(file);
65+ % data = collection_xml.Children(2).Children.Data;
66+ file = tempname ;
67+ fid = fopen(file ,' w' );
68+ fwrite(fid ,data );
69+ % fprintf(fid,data);
70+ fclose(fid );
71+
72+ collection = load_collection(file ,' ' );
0 commit comments