Skip to content

Commit 90e77d6

Browse files
committed
more robust toolbox check
1 parent 68248a8 commit 90e77d6

File tree

14 files changed

+43
-81
lines changed

14 files changed

+43
-81
lines changed

+gemini3d/+plot/mag_map.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ function mag_map(direc)
66

77
gemini3d.sys.check_stdlib()
88

9-
assert(gemini3d.sys.has_mapping(), "Mapping Toolbox is needed")
10-
119
direc = stdlib.expanduser(direc);
1210

1311
%SIMULATION location
@@ -48,21 +46,21 @@ function mag_map(direc)
4846
Bphit=zeros(1,ltheta,lphi, length(cfg.times));
4947

5048
for it=2:length(cfg.times)-1 %starts at second time step due to weird magcalc quirk
51-
filename = gemini3d.datelab(cfg.times(it));
49+
filename = gemini3d.datelab(cfg.times(it)) + ".h5";
5250

53-
data = h5read(fullfile(direc,'magfields', filename + ".h5"), '/magfields/Br');
51+
data = h5read(fullfile(direc,'magfields', filename), '/magfields/Br');
5452

5553
Brt(:,:,:,it)=reshape(data,[1,ltheta,lphi]);
5654
Brt(:,:,:,it)=Brt(:,ilatsort,:,it);
5755
Brt(:,:,:,it)=Brt(:,:,ilonsort,it);
5856

59-
data = h5read(fullfile(direc, 'magfields', filename + ".h5"), '/magfields/Btheta');
57+
data = h5read(fullfile(direc, 'magfields', filename), '/magfields/Btheta');
6058

6159
Bthetat(:,:,:,it)=reshape(data,[1,ltheta,lphi]);
6260
Bthetat(:,:,:,it)=Bthetat(:,ilatsort,:,it);
6361
Bthetat(:,:,:,it)=Bthetat(:,:,ilonsort,it);
6462

65-
data = h5read(fullfile(direc,'magfields', filename + ".h5"), '/magfields/Bphi');
63+
data = h5read(fullfile(direc,'magfields', filename), '/magfields/Bphi');
6664

6765
Bphit(:,:,:,it)=reshape(data,[1,ltheta,lphi]);
6866
Bphit(:,:,:,it)=Bphit(:,ilatsort,:,it);

+gemini3d/+plot/mapgrid.m

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
figure;
5555
hold on;
5656
flag2D=false;
57-
if gemini3d.sys.has_mapping()
58-
ha=gca;
59-
% axesm('MapProjection','Mercator','MapLatLimit',[-(abs(sourcemlat)+30),abs(sourcemlat)+30],'MapLonLimit',[sourcemlonplot-dmlon/2-10,sourcemlonplot+dmlon/2+10])
57+
ha=gca;
58+
try
59+
% axesm('MapProjection','Mercator','MapLatLimit',[-(abs(sourcemlat)+30),abs(sourcemlat)+30],'MapLonLimit',[sourcemlonplot-dmlon/2-10,sourcemlonplot+dmlon/2+10])
6060
axesm('MapProjection','Mercator', ...
61-
'MapLatLimit', double([-(abs(sourcemlat)+dmlat/2+5),abs(sourcemlat)+dmlat/2+5]), ...
62-
'MapLonLimit', double([sourcemlonplot-dmlon/2-10,sourcemlonplot+dmlon/2+10]))
61+
MapLatLimit=double([-(abs(sourcemlat)+dmlat/2+5),abs(sourcemlat)+dmlat/2+5]), ...
62+
MapLonLimit=double([sourcemlonplot-dmlon/2-10,sourcemlonplot+dmlon/2+10]))
6363
plotfun=@plot3m;
64-
else
65-
ha=gca;
64+
catch e
65+
mappingException(e)
6666
plotfun=@plot3; %no mapping toolbox so we'll do normal plots - the annoying thing is that these should be lon,lat,alt so all the plots statements have to be switched
6767
end
6868
end
@@ -101,7 +101,8 @@
101101
set(h,'LineWidth',LW,'Color',[0 0 0]);
102102
ha=h;
103103
else %this is a 3D grid and we can plot it on a map if the user has the appropriate toolbox(es)
104-
if gemini3d.sys.has_mapping()
104+
105+
try % Mapping Toolbox
105106
% plots are done lat,lon,alt for plot3m
106107
plotfun(mlat(:,1,1),mlon(:,1,1),alt(:,1,1),'LineWidth',LW);
107108
plotfun(mlat(:,1,end),mlon(:,1,end),alt(:,1,end),altlinestyle,'LineWidth',LW);
@@ -170,10 +171,10 @@
170171
z=squeeze(alt(end,end,ix3:xg.lx(3)));
171172
plotfun(x,y,z,altlinestyle,'LineWidth',LW);
172173

173-
xlabel('magnetic longitude (deg.)');
174-
ylabel('magnetic latitude (deg.)');
175-
zlabel('altitidue (km)');
176-
else %plotting is done lon,lat,alt with plot3
174+
catch e
175+
mappingException(e)
176+
177+
%plotting is done lon,lat,alt with plot3
177178
plotfun(mlon(:,1,1),mlat(:,1,1),alt(:,1,1),'LineWidth',LW);
178179
plotfun(mlon(:,1,end),mlat(:,1,end),alt(:,1,end),altlinestyle,'LineWidth',LW);
179180
plotfun(mlon(:,end,1),mlat(:,end,1),alt(:,end,1),'LineWidth',LW);
@@ -241,10 +242,12 @@
241242
z=squeeze(alt(end,end,ix3:xg.lx(3)));
242243
plotfun(x,y,z,altlinestyle,'LineWidth',LW);
243244

244-
xlabel('magnetic latitude (deg.)');
245-
ylabel('magnetic longitude (deg.)');
246-
zlabel('altitidue (km)');
247245
end
246+
247+
xlabel('magnetic longitude (deg.)');
248+
ylabel('magnetic latitude (deg.)');
249+
zlabel('altitude (km)');
250+
248251
h=gca; %now go back and make all lines the same color...
249252
% lline = numel(h.Children);
250253
for iline=1:16 %the last three children are the surface and text label objects
@@ -424,7 +427,7 @@
424427
h=polarplot(terr_theta,terr_r,'c:');
425428
set(h,'LineWidth',LW);
426429
else
427-
if gemini3d.sys.has_mapping()
430+
try % Mapping Toolbox
428431
hold on;
429432
%ax=axis;
430433
coastlat = load('coastlines', 'coastlat').coastlat;
@@ -441,6 +444,8 @@
441444
plotfun(mlatcoast,mloncoast,zeros(size(mlatcoast)),'b-','LineWidth',0.5);
442445
setm(gca,'MeridianLabel','on','ParallelLabel','on','MLineLocation',10,'PLineLocation',10,'MLabelLocation',10,'PLabelLocation',10);
443446
hold off;
447+
catch e
448+
mappingException(e)
444449
end
445450
view(270,35);
446451
axis tight;

+gemini3d/+plot/plotall.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@
7171
% https://www.mathworks.com/help/parallel-computing/choose-between-thread-based-and-process-based-environments.html
7272
if opts.parallel > 1
7373
% specific number of workers requested
74-
if gemini3d.sys.has_parallel()
75-
pool = gcp('nocreate');
76-
if isempty(pool) || pool.NumWorkers ~= optfions.parallel
77-
delete(pool)
78-
parpool('local', opts.parallel)
79-
end
74+
pool = gcp('nocreate');
75+
if isempty(pool) || pool.NumWorkers ~= opts.parallel
76+
delete(pool)
77+
parpool('local', opts.parallel)
8078
end
8179
end
8280
parfor t = cfg.times
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function mappingException(e)
2+
3+
if e.identifier ~= "MATLAB:UndefinedFunction"
4+
rethrow(e)
5+
end
6+
7+
disp('Fallback to non-Mapping Toolbox functions')
8+
9+
end

+gemini3d/+sys/has_addon.m

Lines changed: 0 additions & 8 deletions
This file was deleted.

+gemini3d/+sys/has_mapping.m

Lines changed: 0 additions & 5 deletions
This file was deleted.

+gemini3d/+sys/has_parallel.m

Lines changed: 0 additions & 5 deletions
This file was deleted.

+gemini3d/+sys/mpi_path.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
path_new = getenv("PATH");
55

6-
if ~gemini3d.sys.has_parallel()
6+
if ~stdlib.has_parallel_toolbox()
77
return
88
end
99

+gemini3d/private/close_pool.m

Lines changed: 0 additions & 10 deletions
This file was deleted.

cmake/options.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ option(hwm14 "use HWM14 model")
33
option(msis2 "use MSIS2 model" on)
44

55
set_directory_properties(PROPERTIES EP_UPDATE_DISCONNECTED true)
6-
7-
option(CMAKE_TLS_VERIFY "Verify TLS certificates when downloading dependencies" on)

0 commit comments

Comments
 (0)