Skip to content

Commit 175b752

Browse files
committed
accept all variables starting with x and y and unit compatible with metre as x/y-coordinate when listed in Coordinates attribute ... example swanout.nc
1 parent 117e733 commit 175b752

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/tools_lgpl/matlab/quickplot/progsrc/private/nc_interpret.m

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
%
318318
nc.Dataset(ivar) = Info;
319319
end
320-
320+
variablesListedAsCoordinates = unique(cat(2,nc.Dataset.Coordinates));
321321
%
322322
% Detect bounds variables (We don't want bounds directly listed as
323323
% coordinate variable.
@@ -408,6 +408,7 @@
408408
% standard_name not recognized (or time); look for known units
409409
%
410410
j = strmatch('units',Attribs,'exact');
411+
unit = '';
411412
if ~isempty(j)
412413
unit = Info.Attribute(j).Value;
413414
if ~ischar(unit)
@@ -455,9 +456,7 @@
455456
continue
456457
otherwise
457458
try
458-
f = qp_unitconversion(unit1,'Pa');
459-
%
460-
if isnumeric(f)
459+
if unit_equivalent_to(unit1,'Pa')
461460
% dimension unit is compatible with pressure (Pa)
462461
% according CF 1.4 this must be a z-coordinate
463462
nc = setType(nc,ivar,idim,'z-coordinate');
@@ -536,6 +535,17 @@
536535
end
537536
continue
538537
end
538+
%
539+
if ismember(Info.Name,variablesListedAsCoordinates)
540+
% if this should be a coordinate, let's check the variable again
541+
if strncmpi(Info.Name,'x',1) && unit_equivalent_to(unit,'m')
542+
nc = setType(nc,ivar,idim,'x-coordinate');
543+
continue
544+
elseif strncmpi(Info.Name,'y',1) && unit_equivalent_to(unit,'m')
545+
nc = setType(nc,ivar,idim,'y-coordinate');
546+
continue
547+
end
548+
end
539549
end
540550

541551
iCoords = ~strcmp({nc.Dataset.Type},'unknown');
@@ -2289,3 +2299,7 @@
22892299
iedge(ia) = [];
22902300
iface(ia) = [];
22912301
EFC(iedge,2) = iface;
2302+
2303+
function bool = unit_equivalent_to(unit,unit_ref)
2304+
f = qp_unitconversion(unit,unit_ref);
2305+
bool = isnumeric(f);

0 commit comments

Comments
 (0)