-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d8bf22e
Showing
11 changed files
with
603 additions
and
0 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,62 @@ | ||
function [d,response] = datacategories(c,id,varargin) | ||
%DATACATEGORIES NOAA data category name and identifiers. | ||
% [DATA,RESPONSE] = DATACATEGORIES(C) returns up to 25 category names | ||
% and identifiers. C is the NOAA object. | ||
% | ||
% [DATA,RESPONSE] = DATACATEGORIES(C,ID) returns the category name | ||
% and identifier for a given category identifier, ID. C is the NOAA | ||
% object. | ||
% | ||
% [DATA,RESPONSE] = DATACATEGORIES(C,ID,VARARGIN) returns category names | ||
% and identifiers. C is the NOAA object, ID is a category identifier and | ||
% VARARGIN is name and value parameters supported by the NOAA REST API. | ||
% | ||
% See also NOAA. | ||
|
||
% Copyright 2022 The MathWorks, Inc. | ||
|
||
% Set request parameters | ||
method = "GET"; | ||
|
||
% Create URL | ||
datacatagoriesUrl = strcat(c.URL,"datacategories"); | ||
if exist('id','var') && ~isempty(id) | ||
datacatagoriesUrl = strcat(datacatagoriesUrl,"/",id); | ||
end | ||
|
||
% Add name value pairs | ||
if nargin > 2 | ||
datacatagoriesUrl = strcat(datacatagoriesUrl,"?"); | ||
|
||
for i = 1:2:length(varargin) | ||
datacatagoriesUrl = strcat(datacatagoriesUrl,varargin{i},"=",string(varargin{i+1}),"&"); | ||
end | ||
end | ||
|
||
HttpURI = matlab.net.URI(datacatagoriesUrl); | ||
|
||
HttpHeader = matlab.net.http.HeaderField("token",c.Token,"Content-Type","application/json; charset=UTF-8"); | ||
|
||
RequestMethod = matlab.net.http.RequestMethod(method); | ||
Request = matlab.net.http.RequestMessage(RequestMethod,HttpHeader); | ||
|
||
options = matlab.net.http.HTTPOptions('ConnectTimeout',200,'Debug',c.DebugModeValue); | ||
|
||
% Send Request | ||
response = send(Request,HttpURI,options); | ||
|
||
% Convert output to table | ||
if isfield(response.Body.Data,"results") | ||
d = struct2table(response.Body.Data.results); | ||
else | ||
d = struct2table(response.Body.Data); | ||
end | ||
|
||
% Convert cell arrays to string arrays | ||
varNames = d.Properties.VariableNames; | ||
for i = 1:length(varNames) | ||
switch varNames{i} | ||
case {"name","id"} | ||
d.(varNames{i}) = string(d.(varNames{i})); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function [d,response] = datasets(c,id,varargin) | ||
%DATASETS NOAA dataset information. | ||
% [DATA,RESPONSE] = DATASETS(C) returns up to 25 records containing | ||
% information pertaining to the available NOAA datasets | ||
% | ||
% [DATA,RESPONSE] = DATASETS(C,ID) returns the dataset information for a | ||
% given dataset identifier, ID. C is the NOAA | ||
% object. | ||
% | ||
% [DATA,RESPONSE] = DATASETS(C,ID,VARARGIN) returns dataset information. | ||
% C is the NOAA object, ID is a dataset identifier and VARARGIN is name | ||
% and value parameters supported by the NOAA REST API. | ||
% | ||
% See also NOAA. | ||
|
||
% Copyright 2022 The MathWorks, Inc. | ||
|
||
% Set request parameters | ||
method = "GET"; | ||
|
||
% Create URL | ||
datasetsUrl = strcat(c.URL,"datasets"); | ||
if exist('id','var') && ~isempty(id) | ||
datasetsUrl = strcat(datasetsUrl,"/",id); | ||
end | ||
|
||
% Add name value pairs | ||
if nargin > 2 | ||
datasetsUrl = strcat(datasetsUrl,"?"); | ||
|
||
for i = 1:2:length(varargin) | ||
datasetsUrl = strcat(datasetsUrl,varargin{i},"=",string(varargin{i+1}),"&"); | ||
end | ||
end | ||
|
||
HttpURI = matlab.net.URI(datasetsUrl); | ||
|
||
HttpHeader = matlab.net.http.HeaderField("token",c.Token,"Content-Type","application/json; charset=UTF-8"); | ||
|
||
RequestMethod = matlab.net.http.RequestMethod(method); | ||
Request = matlab.net.http.RequestMessage(RequestMethod,HttpHeader); | ||
|
||
options = matlab.net.http.HTTPOptions('ConnectTimeout',200,'Debug',c.DebugModeValue); | ||
|
||
% Send Request | ||
response = send(Request,HttpURI,options); | ||
|
||
if isfield(response.Body.Data,"results") | ||
d = struct2table(response.Body.Data.results); | ||
else | ||
d = struct2table(response.Body.Data); | ||
end | ||
|
||
% Convert cell arrays to string arrays | ||
varNames = d.Properties.VariableNames; | ||
for i = 1:length(varNames) | ||
switch varNames{i} | ||
case {"uid","name","id"} | ||
d.(varNames{i}) = string(d.(varNames{i})); | ||
case {"mindate","maxdate"} | ||
d.(varNames{i}) = datetime(d.(varNames{i})); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
function [d,response] = datatypes(c,id,varargin) | ||
%DATATYPES NOAA data types information. | ||
% [DATA,RESPONSE] = DATATYPES(C) returns up to 25 records containing | ||
% information pertaining to the available NOAA data types. | ||
% | ||
% [DATA,RESPONSE] = DATATYPES(C,ID) returns the data type information for a | ||
% given data type identifier, ID. C is the NOAA | ||
% object. | ||
% | ||
% [DATA,RESPONSE] = DATATYPES(C,ID,VARARGIN) returns data type information. | ||
% C is the NOAA object, ID is a data type identifier and VARARGIN is name | ||
% and value parameters supported by the NOAA REST API. | ||
% | ||
% See also NOAA. | ||
|
||
% Copyright 2022 The MathWorks, Inc. | ||
% Set request parameters | ||
method = "GET"; | ||
|
||
% Create URL | ||
datatypesUrl = strcat(c.URL,"datatypes"); | ||
if exist('id','var') && ~isempty(id) | ||
datatypesUrl = strcat(datatypesUrl,"/",id); | ||
end | ||
|
||
% Add name value pairs | ||
if nargin > 2 | ||
datatypesUrl = strcat(datatypesUrl,"?"); | ||
|
||
for i = 1:2:length(varargin) | ||
datatypesUrl = strcat(datatypesUrl,varargin{i},"=",string(varargin{i+1}),"&"); | ||
end | ||
end | ||
|
||
HttpURI = matlab.net.URI(datatypesUrl); | ||
|
||
HttpHeader = matlab.net.http.HeaderField("token",c.Token,"Content-Type","application/json; charset=UTF-8"); | ||
|
||
RequestMethod = matlab.net.http.RequestMethod(method); | ||
Request = matlab.net.http.RequestMessage(RequestMethod,HttpHeader); | ||
|
||
options = matlab.net.http.HTTPOptions('ConnectTimeout',200,'Debug',c.DebugModeValue); | ||
|
||
% Send Request | ||
response = send(Request,HttpURI,options); | ||
|
||
try | ||
if isfield(response.Body.Data,"results") | ||
d = struct2table(response.Body.Data.results); | ||
else | ||
d = struct2table(response.Body.Data); | ||
end | ||
catch | ||
% Unstructured data return | ||
d = response; | ||
return | ||
end | ||
|
||
% Convert cell arrays to string arrays | ||
varNames = d.Properties.VariableNames; | ||
for i = 1:length(varNames) | ||
switch varNames{i} | ||
case {"name","id"} | ||
d.(varNames{i}) = string(d.(varNames{i})); | ||
case {"mindate","maxdate"} | ||
d.(varNames{i}) = datetime(d.(varNames{i})); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
function [d,response] = getdata(c,id,startdate,enddate,varargin) | ||
%GETDATA NOAA dataset data. | ||
% [DAT,RESPONSE] = GETDATA(C,ID,STARTDATE,ENDDATE) returns the data for a | ||
% given NOAA object C and dataset identifier ID for the date range | ||
% defined by STARTDATE and ENDDATE. | ||
% | ||
% [DAT,RESPONSE] = GETDATA(C,ID,STARTDATE,ENDDATE,VARARGIN) returns the data for a | ||
% given NOAA object C and dataset identifier ID for the date range | ||
% defined by STARTDATE and ENDDATE. VARARGIN is name and value parameters | ||
% supported by the NOAA REST API. | ||
% | ||
% See also NOAA. | ||
|
||
% Copyright 2022 The MathWorks, Inc. | ||
|
||
% Set request parameters | ||
method = "GET"; | ||
|
||
% Create URL | ||
dataUrl = strcat(c.URL,"data"); | ||
|
||
% Add datasetid | ||
if exist("id","var") && ~isempty(id) | ||
varargin = [{"datasetid" id} varargin]; | ||
else | ||
error("datafeed:noaa:missingDataSetId","Dataset identifier required.") | ||
end | ||
|
||
% Add startdate | ||
if exist("startdate","var") && ~isempty(startdate) | ||
startdate = matlab.datetime.compatibility.convertDatenum(startdate); | ||
startdate.Format = "yyyy-MM-dd"; | ||
varargin{end+1} = "startdate"; | ||
varargin{end+1} = string(startdate); | ||
else | ||
error("datafeed:noaa:missingStartDate","Start date required.") | ||
end | ||
|
||
% Add enddate | ||
if exist("enddate","var") && ~isempty(enddate) | ||
enddate = matlab.datetime.compatibility.convertDatenum(enddate); | ||
enddate.Format = "yyyy-MM-dd"; | ||
varargin{end+1} = "enddate"; | ||
varargin{end+1} = string(enddate); | ||
else | ||
error("datafeed:noaa:missingEndDate","End date required.") | ||
end | ||
|
||
% Add name value pairs | ||
if nargin > 1 | ||
dataUrl = strcat(dataUrl,"?"); | ||
|
||
for i = 1:2:length(varargin) | ||
dataUrl = strcat(dataUrl,varargin{i},"=",string(varargin{i+1}),"&"); | ||
end | ||
end | ||
dataUrl{end}(end) = []; | ||
|
||
HttpURI = matlab.net.URI(dataUrl); | ||
|
||
HttpHeader = matlab.net.http.HeaderField("token",c.Token,"Content-Type","application/json; charset=UTF-8"); | ||
|
||
RequestMethod = matlab.net.http.RequestMethod(method); | ||
Request = matlab.net.http.RequestMessage(RequestMethod,HttpHeader); | ||
|
||
options = matlab.net.http.HTTPOptions('ConnectTimeout',200,'Debug',c.DebugModeValue); | ||
|
||
% Send Request | ||
response = send(Request,HttpURI,options); | ||
|
||
if isfield(response.Body.Data,"results") | ||
d = struct2table(response.Body.Data.results); | ||
else | ||
try | ||
d = struct2table(response.Body.Data); | ||
catch | ||
d = response; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
function [d,response] = locationcategories(c,id,varargin) | ||
%LOCATIONCATEGORIES NOAA location category name and identifiers. | ||
% [DATA,RESPONSE] = LOCATIONCATEGORIES(C) returns up to 25 location | ||
% category names and identifiers. C is the NOAA object. | ||
% | ||
% [DATA,RESPONSE] = LOCATIONCATEGORIES(C,ID) returns the location | ||
% category name and identifier for a given category identifier, ID. C is | ||
% the NOAA object. | ||
% | ||
% [DATA,RESPONSE] = LOCATIONCATEGORIES(C,ID,VARARGIN) returns location | ||
% category names and identifiers. C is the NOAA object, ID is a location | ||
% category identifier and VARARGIN is name and value parameters supported | ||
% by the NOAA REST API. | ||
% | ||
% See also NOAA. | ||
|
||
% Copyright 2022 The MathWorks, Inc. | ||
|
||
% Set request parameters | ||
method = "GET"; | ||
|
||
% Create URL | ||
locationcatagoriesUrl = strcat(c.URL,"locationcategories"); | ||
if exist('id','var') && ~isempty(id) | ||
locationcatagoriesUrl = strcat(locationcatagoriesUrl,"/",id); | ||
end | ||
|
||
% Add name value pairs | ||
if nargin > 2 | ||
locationcatagoriesUrl = strcat(locationcatagoriesUrl,"?"); | ||
|
||
for i = 1:2:length(varargin) | ||
locationcatagoriesUrl = strcat(locationcatagoriesUrl,varargin{i},"=",string(varargin{i+1}),"&"); | ||
end | ||
end | ||
|
||
HttpURI = matlab.net.URI(locationcatagoriesUrl); | ||
|
||
HttpHeader = matlab.net.http.HeaderField("token",c.Token,"Content-Type","application/json; charset=UTF-8"); | ||
|
||
RequestMethod = matlab.net.http.RequestMethod(method); | ||
Request = matlab.net.http.RequestMessage(RequestMethod,HttpHeader); | ||
|
||
options = matlab.net.http.HTTPOptions('ConnectTimeout',200,'Debug',c.DebugModeValue); | ||
|
||
% Send Request | ||
response = send(Request,HttpURI,options); | ||
|
||
if isfield(response.Body.Data,"results") | ||
d = struct2table(response.Body.Data.results); | ||
else | ||
d = struct2table(response.Body.Data); | ||
end | ||
|
||
% Convert cell arrays to string arrays | ||
varNames = d.Properties.VariableNames; | ||
for i = 1:length(varNames) | ||
switch varNames{i} | ||
case {"name","id"} | ||
d.(varNames{i}) = string(d.(varNames{i})); | ||
end | ||
end |
Oops, something went wrong.