-
Notifications
You must be signed in to change notification settings - Fork 1
/
ncload.m
30 lines (29 loc) · 1011 Bytes
/
ncload.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [v]=ncload(url,var)
%NCLOAD loads data from all dataset variables (or a single variable)
% into a structure or directly into the workspace
% Usage: [a]=ncgeodataset(url,[var]);
% Inputs: url = name of dataset (local NetCDF file, Grib, remote OPeNDAP, etc)
% [var] = optional variable name.
% If supplied, loads only that variable
% If not supplied, loads all variables
% Output: [v] = optional output structure.
% If supplied, loads variables into structure
% If not supplies, loads variables into workspace
% NCTOOLBOX (https://github.com/nctoolbox/nctoolbox)
nc=ncgeodataset(url);
if nargin==1,
for i=1:length(nc.variables)
vstr=char(nc.variables(i));
if nargout==0,
assignin('base',vstr,nc.data(vstr));
else
eval(sprintf('v.%s=nc.data(''%s'');',vstr,vstr));
end
end
else
if nargout==0,
assignin('base',var,nc.data(var));
else
v=nc.data(var);
end
end