Skip to content

Commit 3e70d8f

Browse files
committed
Support column labels for sample files in comment block based on the same algorithm in Tekal files.
1 parent a53d9f6 commit 3e70d8f

File tree

4 files changed

+94
-30
lines changed

4 files changed

+94
-30
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function ColLabels = getcollabels(ncol,Cmnt)
2+
%getcollabels Extracts column labels from a cell string variable.
3+
% This function searches a cell string argument for lines matching
4+
% [.] column <number> [: or =] string
5+
% where [.] matches any first character (typically a comment line marker
6+
% such as # or %), <number> an integer representing the column number,
7+
% and [: or =] either a colon or equal-sign. Lines for which the number
8+
% exceeds the number of columns are ignored.
9+
%
10+
% Syntax
11+
% columns = getcollabels(nColumns,text)
12+
%
13+
% Input Arguments
14+
% nColumns - Number of columns to return
15+
% text - Cell string containing a header/comment block possibly
16+
% containing lines matching the format described above
17+
%
18+
% Output Argument
19+
% columns - Cell array of length nColumns
20+
21+
%----- LGPL --------------------------------------------------------------------
22+
%
23+
% Copyright (C) 2011-2025 Stichting Deltares.
24+
%
25+
% This library is free software; you can redistribute it and/or
26+
% modify it under the terms of the GNU Lesser General Public
27+
% License as published by the Free Software Foundation version 2.1.
28+
%
29+
% This library is distributed in the hope that it will be useful,
30+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
31+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32+
% Lesser General Public License for more details.
33+
%
34+
% You should have received a copy of the GNU Lesser General Public
35+
% License along with this library; if not, see <http://www.gnu.org/licenses/>.
36+
%
37+
% contact: delft3d.support@deltares.nl
38+
% Stichting Deltares
39+
% P.O. Box 177
40+
% 2600 MH Delft, The Netherlands
41+
%
42+
% All indications and logos of, and references to, "Delft3D" and "Deltares"
43+
% are registered trademarks of Stichting Deltares, and remain the property of
44+
% Stichting Deltares. All rights reserved.
45+
%
46+
%-------------------------------------------------------------------------------
47+
% http://www.deltaressystems.com
48+
% $HeadURL$
49+
% $Id$
50+
51+
ColLabels = repmat({''},1,ncol);
52+
if ~isempty(Cmnt)
53+
for i = 1:length(Cmnt)
54+
[Tk,Rm] = strtok(Cmnt{i});
55+
if ~strcmpi(Tk,'column')
56+
% if the first token isn't "column" try ignoring the first
57+
% character; it might be a comment character.
58+
[Tk,Rm] = strtok(Cmnt{i}(2:end));
59+
end
60+
if (length(Cmnt{i})>10) && strcmpi(Tk,'column')
61+
[a,c,~,idx] = sscanf(Rm,'%i%*[ :=]%c',2);
62+
if (c==2) && a(1)<=ncol && a(1)>0
63+
ColLabels{a(1)} = deblank(Rm(idx-1:end));
64+
end
65+
end
66+
end
67+
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
end
418418

419419
if isempty(FI.X) || isempty(FI.Y)
420-
if (isempty(FI.X) && isempty(FI.Y) && FI.nLoc>1) || ...
420+
if (isempty(FI.X) && isempty(FI.Y) && isscalar(FI.nLoc) && FI.nLoc>1) || ...
421421
(isfield(FI,'Table') && strcmp(FI.Table,'points'))
422422
for i=1:NPar
423423
Out(i+2).DimFlag(2) = 5;

src/tools_lgpl/matlab/quickplot/progsrc/samples.m

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,19 @@
380380
% Correct any mismatch between the number of data columns and the
381381
% number of column labels on the label side ...
382382
%
383-
if length(Params)<n
384-
for i=n:-1:(length(Params)+1)
383+
if isempty(Params)
384+
Params = getcollabels(n,xyz.Header);
385+
for i = 1:n
386+
if isempty(Params{i})
387+
Params{i} = sprintf('Parameter %i',i);
388+
end
389+
end
390+
elseif length(Params) < n
391+
for i = n:-1:(length(Params)+1)
385392
Params{i}=sprintf('Parameter %i',i);
386393
end
387-
elseif length(Params)>n
388-
Params=Params(1:n);
394+
elseif length(Params) > n
395+
Params = Params(1:n);
389396
end
390397
fclose(fid);
391398
catch err
@@ -421,18 +428,18 @@
421428
xyz.Y = [];
422429
xyz.Time = [];
423430
for i = 1:length(xyz.Params)
424-
switch lower(xyz.Params{i})
425-
case {'longitude','lon','x','xp','x-coordinate','x coordinate','x_coordinate','x_gpp','distance','chainage'}
431+
switch lower(strtok(xyz.Params{i}))
432+
case {'longitude','lon','x','xp','x-coordinate','x_coordinate','x_gpp','distance','chainage'}
426433
xyz.X = i;
427-
case {'latitude' ,'lat','y','yp','y-coordinate','y coordinate','y_coordinate','y_gpp'}
434+
case {'latitude' ,'lat','y','yp','y-coordinate','y_coordinate','y_gpp'}
428435
xyz.Y = i;
429436
case 'time'
430437
if i>1 && strcmpi(xyz.Params{i-1},'date')
431438
xyz.Time = [i-1 i];
432439
else
433440
xyz.Time = i;
434441
end
435-
case {'datetime','date and time'}
442+
case {'datetime','date'}
436443
xyz.Time = i;
437444
end
438445
end
@@ -469,7 +476,7 @@
469476
end
470477
end
471478
if isempty(iTime)
472-
[Times,idum,iTime] = unique(gettimes(xyz.XYZ(:,xyz.Time)),'stable');
479+
[Times,idum,iTime] = unique(gettimes(xyz.XYZ(:,xyz.Time),xyz.Params(xyz.Time)),'stable');
473480
nLoc = hist(iTime,max(iTime));
474481
end
475482
%
@@ -517,13 +524,19 @@ function Local_write_samples(filename,header,format,xyz)
517524
fclose(fid);
518525

519526

520-
function Times = gettimes(Times)
527+
function Times = gettimes(Times,ColLabels)
521528
if size(Times,2)==2 % gpp => 20140118 105120
522529
d = Times(:,1);
523530
s = Times(:,2);
524-
else % swan => 20140118.105120
525-
d = floor(Times);
526-
s = round((Times - d)*1000000);
531+
else
532+
switch ColLabels{1}
533+
case 'time (min)'
534+
Times = Times/1440;
535+
return
536+
otherwise % swan => 20140118.105120
537+
d = floor(Times);
538+
s = round((Times - d)*1000000);
539+
end
527540
end
528541
m = floor(d/100);
529542
d = d - 100*m;

src/tools_lgpl/matlab/quickplot/progsrc/tekal.m

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -712,22 +712,6 @@
712712
fclose(fid);
713713

714714

715-
function ColLabels=getcollabels(ncol,Cmnt)
716-
ColLabels={}; % necessary for standalone version
717-
ColLabels(1:ncol,1)={''};
718-
if ~isempty(Cmnt)
719-
for i=1:length(Cmnt)
720-
[Tk,Rm]=strtok(Cmnt{i}(2:end));
721-
if (length(Cmnt{i})>10) && strcmpi(Tk,'column')
722-
[a,c,err,idx]=sscanf(Rm,'%i%*[ :=]%c',2);
723-
if (c==2) && a(1)<=ncol && a(1)>0
724-
ColLabels{a(1)}=deblank(Rm(idx-1:end));
725-
end
726-
end
727-
end
728-
end
729-
730-
731715
function Time=gettimestamp(Cmnt)
732716
Time=[];
733717
if ~isempty(Cmnt)

0 commit comments

Comments
 (0)