Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cfletchg authored Oct 18, 2022
0 parents commit d8bf22e
Show file tree
Hide file tree
Showing 11 changed files with 603 additions and 0 deletions.
62 changes: 62 additions & 0 deletions @noaa/datacategories.m
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
63 changes: 63 additions & 0 deletions @noaa/datasets.m
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
68 changes: 68 additions & 0 deletions @noaa/datatypes.m
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
79 changes: 79 additions & 0 deletions @noaa/getdata.m
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
62 changes: 62 additions & 0 deletions @noaa/locationcategories.m
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
Loading

0 comments on commit d8bf22e

Please sign in to comment.