Skip to content

Commit 194bbba

Browse files
committed
further efforts to make .m codes GNU Octave compatible (see discussion)
1 parent 08c9ae1 commit 194bbba

File tree

15 files changed

+69
-57
lines changed

15 files changed

+69
-57
lines changed

CODE/matlab/.octaverc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%graphics_toolkit gnuplot
2+
addpath superprocs
3+
javaaddpath ('../bin/java/xercesImpl.jar')
4+
javaaddpath ('../bin/java/xml-apis.jar')
5+
pkg load io

CODE/matlab/calib.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
%
1212
% Author: F. Beauducel, WEBOBS/IPGP
1313
% Created: 2004-09-01
14-
% Updated: 2017-02-01
14+
% Updated: 2022-07-24
1515

16-
if isempty(t) | (isscalar(t) & isnan(t))
16+
if isempty(t) || (isscalar(t) && isnan(t))
1717
t = now;
1818
end
1919

2020
if isempty(d)
2121
d = nan(1,CLB.nx);
2222
end
2323

24-
if nargin > 3 & strcmp(lower(cco),'channelcodeorder')
24+
if nargin > 3 && strcmp(lower(cco),'channelcodeorder')
2525
cco = 1;
2626
else
2727
cco = 0;
@@ -59,7 +59,7 @@
5959
col = i;
6060
end
6161
fprintf('WEBOBS{calib}: channel %d ("%s") calibrated from %s column %d (%d data).\n',i,CLB(j).nm{ki(ii)},datestr(tt(ii)),col,length(k))
62-
if CLB(j).vn(ki(ii)) ~= 0 | CLB(j).vm(ki(ii)) ~= 0
62+
if CLB(j).vn(ki(ii)) ~= 0 || CLB(j).vm(ki(ii)) ~= 0
6363
kk = find(d(k,col) < CLB(j).vn(ki(ii)) | d(k,col) > CLB(j).vm(ki(ii)));
6464
if ~isempty(kk)
6565
d(k(kk),col) = NaN;

CODE/matlab/clbselect.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
function X=clbselect(X,s)
22
%CLBSELECT Calibration channel selection
3-
% Y=CLBSELECT(X,CHAN) selects channels CHAN in calibration structure X and
3+
% Y=CLBSELECT(X,CHAN) selects channels CHAN in calibration structure X and
44
% returns new calibration structure Y. CHAN can be either a cell array of
55
% strings with channel names, or a vector of channel numbers, as given in
66
% the node's calibration file.
77
%
88
%
99
% Author: F. Beauducel / WEBOBS
1010
% Created: 2017-01-13 in Yogyakarta, Indonesia
11-
% Updated: 2017-07-27
11+
% Updated: 2022-07-25
1212

13-
if isstr(s)
13+
if ischar(s)
1414
s = cellstr(s);
1515
end
1616

CODE/matlab/mkgraph.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
%
1818
% Authors: F. Beauducel - D. Lafon, WEBOBS/IPGP
1919
% Created: 2002-12-03
20-
% Updated: 2022-06-12
20+
% Updated: 2022-07-25
2121

2222

2323
wofun = sprintf('WEBOBS{%s}',mfilename);
@@ -77,7 +77,7 @@
7777
h1 = plotlogo(G.LOGO2_FILE,G.LOGO2_HEIGHT,'right');
7878

7979
if isfield(G,'GSTATUS')
80-
if G.STATUS & length(G.GSTATUS) > 2 & all(~isnan(G.GSTATUS(2:3)))
80+
if G.STATUS && length(G.GSTATUS) > 2 && all(~isnan(G.GSTATUS(2:3)))
8181
G.GTITLE = [G.GTITLE, ...
8282
{sprintf('%s %+02d - Status %03d %% - Sampling %03d %% ',datestr(G.GSTATUS(1)),G.TZ,round(G.GSTATUS(2:3)))}];
8383
end
@@ -122,7 +122,8 @@
122122
% --- timestamp
123123
if timestamp > 0
124124
ST = dbstack;
125-
superproc = ST(2).file;
125+
[spath,sname,sext] = fileparts(ST(2).file);
126+
superproc = sprintf('%s%s',sname,sext);
126127
w1 = wosystem('echo "$(whoami)@$(hostname)"','chomp','print');
127128
% gets the updated date of superproc's code... (note: mkgraph is always called by a superproc)
128129
[s,w2] = wosystem(sprintf('grep "Updated:" superprocs/%s',superproc),'chomp');
@@ -204,7 +205,11 @@
204205
% --- Creates optional interactive MAP (html map)
205206
% appends IMAP from proc to events
206207
if nargin > 3 && isfield(OPT,'IMAP')
207-
I = cat(2,I,OPT.IMAP);
208+
if ~isempty(I)
209+
I = cat(2,I,OPT.IMAP);
210+
else
211+
I = OPT.IMAP;
212+
end
208213
end
209214

210215
IM = imfinfo(sprintf('%s/%s.png',ptmp,f));
@@ -273,13 +278,16 @@
273278
for i = 1:length(ff)
274279
if exist(ff{i},'file')
275280
try
276-
A = imread(ff{i});
281+
[A,map,alpha] = imread(ff{i});
282+
% applies transparency channel manually (for Octave compatibility)
283+
M = repmat(double(alpha)/255,[1,1,3]);
284+
I = M.*double(A)/255 + (1 - M);
277285
isz = size(A);
278286
lgh = rh*pp(3)/pp(4);
279287
lgw = lgh*isz(2)*pp(4)/isz(1)/pp(3);
280288
posx = pos0 + strcmp(pos,'right')*(1-lgw);
281289
h = axes('Position',[posx,1-lgh,lgw,lgh],'Visible','off');
282-
image(A)
290+
imagesc(I)
283291
axis off
284292
pos0 = pos0 + (lgw + 0.005)*(1 - 2*strcmp(pos,'right'));
285293
catch

CODE/matlab/randname.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%RANDNAME Random name string
33
% RANDNAME returns a random 16-char alpha string.
44
% RANDNAME(N) returns a N-char length.
5-
% RANDNAME(N,NAMES) uses cell array of strings NAMES to ensure a
5+
% RANDNAME(N,NAMES) uses cell array of strings NAMES to ensure a
66
% unique new name.
77
%
88
%
@@ -22,7 +22,7 @@
2222
error('N must be a positive scalar integer.')
2323
end
2424

25-
rng('shuffle');
25+
%rng('shuffle');
2626
s = '';
2727
while isempty(s) || any(strcmp(s,name))
2828
s = char(floor(rand(1,n)*26) + 65 + round(rand(1,n))*32);

CODE/matlab/readfmtdata_gnss.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,12 @@
170170
end
171171

172172
% load the file
173+
dd = [];
173174
if exist(fdat,'file')
174-
dd = load(fdat);
175-
else
176-
dd = [];
175+
F = dir(fdat);
176+
if F.bytes > 0
177+
dd = load(fdat);
178+
end
177179
end
178180
if ~isempty(dd)
179181
% converts GPS J2000 time to datenum

CODE/matlab/readfmtdata_quake.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
%xml = urlread(sprintf('%s&includeallmagnitudes=false&includeallorigins=false&includearrivals=false&%s%s%s',F.raw{1},wsreq,wsreqstime,wsreqetime),'Charset','UTF-8','Timeout',60);
198198
%xml = urlread(sprintf('%s&includeallmagnitudes=false&includeallorigins=false&includearrivals=false&%s%s%s',F.raw{1},wsreq,wsreqstime,wsreqetime));
199199
url = sprintf('%s&includeallmagnitudes=false&includeallorigins=false&includearrivals=false&%s%s%s',F.raw{1},wsreq,wsreqstime,wsreqetime);
200-
s = wosystem(sprintf('wget "%s" -O %s -t 1 -T 60',url,fdat),P);
200+
s = wosystem(sprintf('wget -q "%s" -O %s -t 1 -T 60',url,fdat),P);
201201
if s ~= 0
202202
break;
203203
end

CODE/matlab/readnode.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
%
3434
% Authors: F. Beauducel, D. Lafon, WEBOBS/IPGP
3535
% Created: 2013-02-22
36-
% Updated: 2022-06-12
36+
% Updated: 2022-07-25
3737

3838

3939
if ~exist('NODES','var')
@@ -126,7 +126,7 @@
126126
end
127127
if exist(clb,'file')
128128
fid = fopen(clb);
129-
C = textscan(fid,'%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%*[^\n]','Delimiter','|','CommentStyle','#');
129+
C = textscan(fid,'%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s','Delimiter','|','CommentStyle','#');
130130
fclose(fid);
131131
%[y,m,d,h,n,nv,nm,un,ns,cc,of,et,ga,vn,vm,az,la,lo,al] = textread(f,'%d-%d-%d%d:%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%*[^\n]','delimiter','|','commentstyle','shell');
132132
nn = 1;
@@ -172,14 +172,14 @@
172172
N.CLB = CC;
173173
end
174174

175-
if ~exist('CC','var') | isempty(CC)
175+
if ~exist('CC','var') || isempty(CC)
176176
N.CLB = struct('nx',0,'dt',0,'nv',0,'nm','','un','','ns','','cd','','of',0,'et',0,'ga',0,'vn',0,'vm',0,'az',0,'la',0,'lo',0,'al',0,'dp',0,'sf',NaN,'db','','lc','');
177177
end
178178

179179
% --- transmission type and nodes' list
180180
tr = split(N.TRANSMISSION,'|, ');
181181

182-
if length(tr) > 0 & ~isempty(tr{1})
182+
if length(tr) > 0 && ~isempty(tr{1})
183183
rmfield(N,'TRANSMISSION'); % needed since R2015... (?)
184184
N.TRANSMISSION = struct('TYPE',str2num(tr{1}));
185185
nn = 0;

CODE/matlab/readnodes.m

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
%
88
% N = READNODES(WO,GRIDS,TLIM) specifies date of node's activity. TLIM can be scalar
99
% of vector in DATENUM format. Use TLIM = NOW to import only active nodes; use
10-
% TLIM = DATE or TLIM = [DATE1,DATE2] to get nodes active at a date DATE or in
10+
% TLIM = DATE or TLIM = [DATE1,DATE2] to get nodes active at a date DATE or in
1111
% period between DATE1 and DATE2.
1212
%
1313
% N = READNODES(WO,GRIDS,TLIM,0) forces importation of unvalid nodes. Use TLIM = [] to
@@ -43,20 +43,21 @@
4343
valid = 1;
4444
end
4545

46+
G2N = dir(WO.PATH_GRIDS2NODES);
4647
N = [];
4748
for i = 1:length(grids)
48-
k = 0;
49+
n = 0;
4950
g = grids{i};
50-
X = dir(sprintf('%s/%s.*',WO.PATH_GRIDS2NODES,g));
51-
for j = 1:length(X)
52-
nodefullid = split(X(j).name,'.');
51+
k = find(strncmp([g,'.'],{G2N.name},length(g)+1));
52+
for j = 1:length(k)
53+
nodefullid = split(G2N(k(j)).name,'.');
5354
% avoid duplicates
5455
if isempty(N) || ~any(ismember(nodefullid{3},cat(1,{N.ID})))
55-
NN = readnode(WO,X(j).name,NODES);
56+
NN = readnode(WO,G2N(k(j)).name,NODES);
5657
if ~isempty(NN) && (~valid || NN.VALID) ...
5758
&& (isnan(tlim(1)) || isnan(NN.END_DATE) || NN.END_DATE >= tlim(1)) ...
5859
&& (isnan(tlim(2)) || isnan(NN.INSTALL_DATE) || NN.INSTALL_DATE <= tlim(2))
59-
k = k + 1;
60+
n = n + 1;
6061
if isempty(N)
6162
N = NN;
6263
else
@@ -66,11 +67,9 @@
6667
end
6768
end
6869
if nargin > 0
69-
fprintf('WEBOBS{readnodes}: %d/%d nodes imported from grid %s.\n',k,length(X),g);
70+
fprintf('WEBOBS{readnodes}: %d/%d nodes imported from grid %s.\n',n,length(k),g);
7071
end
7172
end
7273

7374

7475
fprintf('WEBOBS{readnodes}: %d nodes returned.\n',length(N));
75-
76-

CODE/matlab/readproc.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
%
2424
% Authors: F. Beauducel, D. Lafon, WEBOBS/IPGP
2525
% Created: 2013-04-05
26-
% Updated: 2021-01-01
26+
% Updated: 2022-07-22
2727

2828

2929
proc = varargin{1};
@@ -83,16 +83,18 @@
8383

8484
% appends the list of nodes (i.e., creates field P.NODESLIST)
8585
% list directory WO.PATH_GRIDS2NODES for PROC.n, appends to P as NODESLIST
86-
X = dir(sprintf('%s/PROC.%s.*',WO.PATH_GRIDS2NODES,proc));
86+
X = dir(WO.PATH_GRIDS2NODES);
87+
k = find(strncmp(['PROC.' proc],{X.name},length(proc)+5));
8788
P.NODESLIST = {};
88-
for j = 1:length(X)
89-
nj = split(X(j).name,'.');
89+
for j = 1:length(X(k))
90+
nj = split(X(k(j)).name,'.');
9091
P.NODESLIST{end+1} = nj{3};
9192
end
9293
% appends the associated FORM (if exists) by listing directory WO.PATH_GRIDS2FORMS
93-
X = dir(sprintf('%s/PROC.%s.*',WO.PATH_GRIDS2FORMS,proc));
94-
if ~isempty(X)
95-
form = split(X(1).name,'.');
94+
X = dir(WO.PATH_GRIDS2FORMS);
95+
k = find(strncmp(['PROC.' proc],{X.name},length(proc)+5));
96+
if ~isempty(k)
97+
form = split(X(k).name,'.');
9698
formname = form{3};
9799
formroot = sprintf('%s/%s',WO.PATH_FORMS,formname);
98100
P.FORM = readcfg(WO,sprintf('%s/%s.conf',formroot,formname));
@@ -131,7 +133,7 @@
131133
if nargin < 4
132134
tscale = {'%'};
133135
if nargin > 2
134-
if isstr(varargin{2})
136+
if ischar(varargin{2})
135137
% in deployed application, input arguments are only string
136138
if isdeployed && numel(str2num(varargin{2}))==2
137139
tscale = str2num(varargin{2});

CODE/matlab/selectnode.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
%
1818
% Author: F. Beauducel
1919
% Created: 2021-01-17 in Yogyakarta, Indonesia
20+
% Updated: 2022-07-22
2021

2122
% selects from lifetime dates
2223
date1 = cat(1,N.INSTALL_DATE);
@@ -43,6 +44,6 @@
4344
% (re)includes some nodes
4445
if nargin > 3 && ~isempty(incl)
4546
ki = find(ismemberlist({N.FID},split(incl,',')));
46-
k = unique([k,ki]);
47+
k = unique([k;ki(:)]);
4748
end
4849
fprintf('---> %d/%d nodes selected.\n',numel(k),numel(N));

CODE/matlab/strjoin.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
ss = cell(2,n);
1313
ss(1,:) = reshape(c,1,n);
1414
ss(2,1:n-1) = {d};
15+
ss{end} = '';
1516
s = [ss{:}];

CODE/matlab/superprocs/gnss.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@
827827
[xx,yy] = meshgrid(DEM.lon,DEM.lat);
828828
DEM.dist = greatcircle(targetll(1),targetll(2),yy,xx);
829829
[c,h] = contour(DEM.lon,DEM.lat,DEM.dist,'k');
830-
set(h,'Color',modelling_topo_rgb,'LineWidth',.1);
830+
set(h,'LineColor',modelling_topo_rgb,'LineWidth',.1);
831831
clabel(c,h,'FontSize',8,'Color',modelling_topo_rgb);
832832
end
833833

@@ -895,8 +895,8 @@
895895
sta_amp = sqrt(rsum(tr(knv,vectors_ampcmp).^2,2));
896896
sta_err = sqrt(rsum(tre(knv,vectors_ampcmp).^2,2));
897897
for nn = 1:numel(knv)
898-
n = knv(nn);
899-
errorbar(sta_dist(nn),sta_amp(nn),sta_err(nn),'.','MarkerSize',15,'Color',scolor(n),'LineWidth',0.1)
898+
h = errorbar(sta_dist(nn),sta_amp(nn),sta_err(nn),'.');
899+
set(h,'MarkerSize',15,'Color',scolor(knv(nn)),'LineWidth',0.1);
900900
end
901901
hold off
902902
set(gca,'FontSize',8)

CODE/matlab/superprocs/sefran3.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function sefran3(name,fdate)
2020
% Authors: Francois Beauducel, Didier Lafon, Alexis Bosson, Jean-Marie Saurel, WEBOBS/IPGP
2121
% Created: 2012-02-09 in Paris, France
2222
% (based on legacy sefran.m, 2002 and sefran2.m, 2007)
23-
% Updated: 2022-07-22
23+
% Updated: 2022-07-24
2424

2525
WO = readcfg;
2626
wofun = sprintf('WEBOBS{%s}',mfilename);
@@ -339,12 +339,11 @@ function sefran3(name,fdate)
339339
text(xlim(2)/2,0,{s,''}, ...
340340
'HorizontalAlignment','center','VerticalAlignment','bottom','FontSize',7,'FontWeight','bold','Color',.8*[1,1,1],'Interpreter','none')
341341
end
342-
text(xlim(2)/2,0,datestr(t0,'yyyy-mm-dd HH:MM'), ...
343-
'HorizontalAlignment','center','VerticalAlignment','bottom','FontSize',9,'Color','k','Interpreter','none')
344-
text(xlim,[0,0],{'|','|'}, ...
345-
'HorizontalAlignment','center','VerticalAlignment','bottom','FontSize',9,'Fontweight','Bold','Color','k')
346-
text(xlim,repmat(ylim(1),[1,2]),{datestr(t0,'|\nHH:MM\nyyyy-mm-dd');datestr(t1,'|\nHH:MM\nyyyy-mm-dd')}, ...
347-
'HorizontalAlignment','center','VerticalAlignment','top','FontSize',9,'Fontweight','Bold','Color','k')
342+
opt = {'HorizontalAlignment','center','FontSize',9,'Color','k','Interpreter','none'};
343+
text(xlim(2)/2,0,datestr(t0,'yyyy-mm-dd HH:MM'),'VerticalAlignment','bottom',opt{:})
344+
text(xlim,[0,0],{'|','|'},'VerticalAlignment','bottom',opt{:})
345+
text(xlim(1),ylim(1),{'|',datestr(t0,'HH:MM'),datestr(t0,'yyyy-mm-dd')},'FontWeight','bold','VerticalAlignment','top',opt{:})
346+
text(xlim(2),ylim(1),{'|',datestr(t1,'HH:MM'),datestr(t1,'yyyy-mm-dd')},'FontWeight','bold','VerticalAlignment','top',opt{:})
348347
if xtickinterval
349348
xt = (0:xtickinterval:60)/86400;
350349
plot(repmat(xt,[2,1]),ylim(1)-repmat([0;.01*ylim(1)],[1,size(xt,2)]),'-','Color','k','LineWidth',.2);

CODE/matlab/timeplot.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
% Created: 2015-08-25 in Yogyakarta, Indonesia
1717
% Updated: 2019-10-23
1818

19-
if nargin < 2
20-
error('Not enough input argument.')
21-
end
22-
2319
dt = diff(t);
2420

2521
if nargin < 3
@@ -49,4 +45,3 @@
4945
if nargout > 0
5046
varargout{1} = h;
5147
end
52-

0 commit comments

Comments
 (0)