-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from CelsoReyes/working
Working
- Loading branch information
Showing
14 changed files
with
519 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
classdef MyProgressMonitorNew < matlab.net.http.ProgressMonitor | ||
properties | ||
ProgHandle | ||
Direction matlab.net.http.MessageType | ||
Value uint64 | ||
NewDir matlab.net.http.MessageType = matlab.net.http.MessageType.Request | ||
end | ||
|
||
methods | ||
function obj = MyProgressMonitorNew | ||
obj.Interval = .01; | ||
end | ||
|
||
function done(obj) | ||
obj.closeit(); | ||
end | ||
|
||
function delete(obj) | ||
obj.closeit(); | ||
end | ||
|
||
function set.Direction(obj, dir) | ||
obj.Direction = dir; | ||
obj.changeDir(); | ||
end | ||
|
||
function set.Value(obj, value) | ||
obj.Value = value; | ||
obj.update(); | ||
end | ||
end | ||
|
||
methods (Access = private) | ||
function update(obj,~) | ||
% called when Value is set | ||
import matlab.net.http.* | ||
if ~isempty(obj.Value) | ||
if isempty(obj.Max) | ||
% no maximum means we don't know length, so message changes on | ||
% every call | ||
value = 0; | ||
if obj.Direction == MessageType.Request | ||
msg = sprintf('Sent %d bytes...', obj.Value); | ||
else | ||
msg = sprintf('Received %d bytes...', obj.Value); | ||
end | ||
else | ||
% maximum known; update proportional value | ||
value = double(obj.Value)/double(obj.Max); | ||
if obj.NewDir == MessageType.Request | ||
% message changes only on change of direction | ||
if obj.Direction == MessageType.Request | ||
msg = 'Sending...'; | ||
else | ||
msg = 'Receiving...'; | ||
end | ||
end | ||
end | ||
if isempty(obj.ProgHandle) | ||
% if we don't have a progress bar, display it for first time | ||
obj.ProgHandle = ... | ||
waitbar(value, msg, 'CreateCancelBtn', @(~,~)cancelAndClose(obj)); | ||
|
||
obj.NewDir = MessageType.Response; | ||
elseif obj.NewDir == MessageType.Request || isempty(obj.Max) | ||
% on change of direction or if no maximum known, change message | ||
waitbar(value, obj.ProgHandle, msg); | ||
obj.NewDir = MessageType.Response; | ||
else | ||
% no direction change else just update proportional value | ||
waitbar(value, obj.ProgHandle); | ||
end | ||
end | ||
|
||
function cancelAndClose(obj) | ||
% Call the required CancelFcn and then close our progress bar. This is | ||
% called when user clicks cancel or closes the window. | ||
obj.CancelFcn(); | ||
obj.closeit(); | ||
end | ||
end | ||
|
||
function changeDir(obj,~) | ||
% Called when Direction is set or changed. Leave the progress bar displayed. | ||
obj.NewDir = matlab.net.http.MessageType.Request; | ||
end | ||
end | ||
|
||
methods (Access=private) | ||
function closeit(obj) | ||
% Close the progress bar by deleting the handle so CloseRequestFcn isn't | ||
% called, because waitbar calls our cancelAndClose(), which would cause | ||
% recursion. | ||
if ~isempty(obj.ProgHandle) | ||
delete(obj.ProgHandle); | ||
obj.ProgHandle = []; | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
% dealing with fdsn data more-or-less directly | ||
% this is a temporary script, and should be rolled into the | ||
% FDSN import routines | ||
% with the anticipation that matlab.net.http.ProgressMonitor | ||
% will be used to provide feedback. | ||
|
||
% U = matlab.net.URI('http://service.iris.edu/fdsnws/event/1/query?starttime=2018-01-11T00:00:00&orderby=time&format=text&nodata=404'); | ||
tic | ||
U = matlab.net.URI('http://service.iris.edu/fdsnws/event/1/query?starttime=2018-09-11T00:00:00&orderby=time&format=text&nodata=404'); | ||
method = matlab.net.http.RequestMethod.GET; | ||
type1 = matlab.net.http.MediaType('text/*'); | ||
acceptField = matlab.net.http.field.AcceptField([type1]); | ||
contentTypeField = matlab.net.http.field.ContentTypeField('text/plain'); | ||
header = [acceptField contentTypeField]; | ||
request = matlab.net.http.RequestMessage(method,header); | ||
|
||
consumer=matlab.net.http.io.StringConsumer; | ||
|
||
[resp,req,hist] = request.send(U,matlab.net.http.HTTPOptions('SavePayload',true,'ProgressMonitorFcn',@MyProgressMonitorNew,'UseProgressMonitor',true),consumer); | ||
% show(request) | ||
% resp.show | ||
|
||
% if there is an error, it would be shown in hist.Response.Body.Data | ||
ss=strsplit(string(char(resp.Body.Data')),newline)'; | ||
numel(ss) | ||
%% | ||
f=fopen('junkk.dat','w'); | ||
fprintf(f,"%s",resp.Body.Data); %resp.Body.Payload | ||
fclose(f); | ||
%% | ||
ZG.primeCatalog = import_fdsn_event(1,'junk.dat') | ||
% ZmapMainWindow(ZG.primeCatalog) | ||
toc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.