-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ncexists: 2-10x speedup, scalar variable
- Loading branch information
Showing
4 changed files
with
26 additions
and
23 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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
function exists = ncexists(file, vars) | ||
function exists = ncexists(file, variable) | ||
|
||
arguments | ||
file (1,1) string {mustBeFile} | ||
vars string | ||
variable string {mustBeScalarOrEmpty} | ||
end | ||
|
||
% NOT contains because we want exact string match | ||
exists = ismember(vars, stdlib.hdf5nc.ncvariables(file)); | ||
exists = false; | ||
|
||
try | ||
ncinfo(file, variable); | ||
exists = true; | ||
catch e | ||
if ~any(contains(e.identifier, ["MATLAB:imagesci:netcdf:badLocationString", "MATLAB:imagesci:netcdf:unknownLocation"])) | ||
rethrow(e) | ||
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
function exists = ncexists(file, vars) | ||
%% ncexists(file, vars) | ||
% check if variable(s) exists in NetCDF4 file | ||
function exists = ncexists(file, variable) | ||
%% ncexists(file, variable) | ||
% check if variable exists in NetCDF4 file | ||
% | ||
%%% Inputs | ||
% * file: data filename | ||
% * varname: path(s) of variable in file | ||
% * variable: path of variable in file | ||
% | ||
%%% Outputs | ||
% * exists: boolean (scalar or vector) | ||
% * exists: boolean | ||
|
||
arguments | ||
file (1,1) string {mustBeFile} | ||
vars string | ||
file (1,1) string | ||
variable string {mustBeScalarOrEmpty} | ||
end | ||
|
||
exists = stdlib.hdf5nc.ncexists(file, vars); | ||
exists = stdlib.hdf5nc.ncexists(file, variable); | ||
|
||
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